public HttpStatusCode AddNewAdditionalContact(AdditionalContact newAdditionalContact) { var smAlreadyExists = _db.AdditionalContacts.Any(c => c.Email == newAdditionalContact.Email); if (smAlreadyExists) { return(HttpStatusCode.Conflict); } try { _db.AdditionalContacts.Add(newAdditionalContact); _db.SaveChanges(); _mongoMongoLogger.SuccessfullyAddedServerLog(HttpContext.Current.User, newAdditionalContact); return(HttpStatusCode.OK); } catch (Exception ex) { _mongoMongoLogger.FailedToCreateServerLog(HttpContext.Current.User, ex.Message, ex.InnerException, newAdditionalContact); return(HttpStatusCode.InternalServerError); } }
public HttpStatusCode AddNewPrimaryContact(PrimaryContact newContact) { bool contactAlreadyExists = _db.PrimaryContacts.Any(c => c.Email == newContact.Email); if (!contactAlreadyExists) { try { _db.PrimaryContacts.Add(newContact); _db.SaveChanges(); return(HttpStatusCode.OK); } catch (Exception ex) { _mongoMongoLogger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message, ex.InnerException, newContact); return(HttpStatusCode.InternalServerError); } } else { return(HttpStatusCode.Conflict); } }
public void UpdateAddress(Address address) { //var addressToUpdate = _db.Addresses.FirstOrDefault(a => a.Id == address.Id); var addressToUpdate = _db.Addresses.Find(address.Id); var addressBeforeUpdate = DtoHelper.CreateAddressDto(addressToUpdate); try { addressToUpdate.Active = address.Active; addressToUpdate.AddressLineOne = address.AddressLineOne; addressToUpdate.AddressLineTwo = address.AddressLineTwo; addressToUpdate.AddressLineThree = address.AddressLineThree; addressToUpdate.AddressLineFour = address.AddressLineFour; addressToUpdate.City = address.City; addressToUpdate.Country = address.Country; addressToUpdate.RegionCounty = address.RegionCounty; addressToUpdate.Postcode = address.Postcode; addressToUpdate.Version = addressToUpdate.Version + 1; addressToUpdate.Level = address.Level; addressToUpdate.DeliveryNote = address.DeliveryNote; _db.SaveChanges(); //_unitOfWork.Complete(); _mongoMongoLogger.SuccessfulUpdateServerLog(HttpContext.Current.User, addressBeforeUpdate, addressToUpdate); } catch (Exception ex) { _mongoMongoLogger.FailedUpdateServerLog <Exception, object, object>(HttpContext.Current.User, ex.Message, ex.InnerException, address); } }
public void CalculateChildrenAllGlns() { foreach (var gln in _db.Glns) { gln.NumberOfChildren = CalculateChildrenNumbers(gln.OwnGln); var parent = _unitOfWork.Glns.Find(p => gln.ParentGln == p.OwnGln); if (!Equals(parent, null) && !gln.Primary) { gln.ParentDescriptionPurpose = parent.FirstOrDefault(p => p.OwnGln == gln.ParentGln).FriendlyDescriptionPurpose; } } _db.SaveChanges(); }