Skip to content

Instantly share code, notes, and snippets.

View nunofilipecosta's full-sized avatar
👨‍💻
coding

Nuno Costa nunofilipecosta

👨‍💻
coding
View GitHub Profile
@nunofilipecosta
nunofilipecosta / save.cs
Created July 30, 2014 07:54
After save , if it doesn't exists throw exception
var transportOrder = _appService.FindById<TransportOrder>(transportOrderId);
transportOrder.ReceiveLoadGuid = closedLoadId;
Save(transportOrder);
if (transportOrder == null)
{
throw new ArgumentNullException("transportOrderId");
}
@nunofilipecosta
nunofilipecosta / string.cs
Created July 30, 2014 07:50
Bad use of string.Format
ret.Add(string.Format(Error.TransportOrderAlreadyExists + string.Empty, transportOrder.LoadNumber));
@nunofilipecosta
nunofilipecosta / Searcher.cs
Created January 28, 2014 12:37
Serch for all or for searchTerm
public class Searcher
{
public void Search(string searchTerm = null)
{
// .Where(r => searchTerm == null || r.Name.Contains(searchTerm))
}
}
@nunofilipecosta
nunofilipecosta / ModelState.cs
Created October 25, 2013 07:47
ModelState to String Array
var errorInModelState = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors).Select(k => k.ErrorMessage);
return Request.CreateResponse(HttpStatusCode.BadRequest, errorInModelState);
@nunofilipecosta
nunofilipecosta / repository.cs
Created October 22, 2013 15:17
Check generated sql script for query
((ObjectQuery<OpenGoodsReceiptFilteredTransporters>)query).ToTraceString();
@nunofilipecosta
nunofilipecosta / EmailAttribute.cs
Created September 18, 2013 11:35
EmailAttribute
using System;
using System.ComponentModel.DataAnnotations;
namespace MocheRandomGeneration.Core.Utilities.ValidationAttributes
{
[AttributeUsage(AttributeTargets.Property)]
public sealed class EmailAttribute : RegularExpressionAttribute
{
public EmailAttribute() : base(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}")
{
@nunofilipecosta
nunofilipecosta / DatabaseExceptionConverter.cs
Created September 18, 2013 11:25
Database Raise Error exception converter
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Reflection;
using System.Text.RegularExpressions;
namespace Utilities.Database
{
/// <summary>
/// Converts exceptions thrown by the DB into the correct exception
@nunofilipecosta
nunofilipecosta / repository.cs
Created September 12, 2013 18:12
Entity Framework Update
public void Update(Entity currentEntity)
{
using(var db = new Context())
{
db.DbSet.Attach(currentEntity);
db.Entry(currentEntity).State = EntityState.Modified;
// V4
////context.ObjectStateManager.ChangeObjectState(currentEntity, EntityState.Modified);
db.SaveChanges();
}
@nunofilipecosta
nunofilipecosta / mobilephonept
Created August 21, 2013 10:32
mobilephonept; email ;
var mobilePhonePt = new Regex(@"^9(1|2|3|6)\d{7}$");
var email = new Regex(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}");
@nunofilipecosta
nunofilipecosta / PackageManagerConsole
Last active December 20, 2015 23:19
Re-Install a nuget package
Update-Package [PackageId] -Reinstall