public bool Upsert(PropertyInformationViewModel viewModel) { try { using (var context = new ChainsDBEntities()) { var insert = viewModel.Id == _guidRepository.EmptyGuid(); Property propertyToUpsert; if (insert) { var buyerCode = GetNewCode(); _databaseRepository.AddItem(context, buyerCode); var sellerCode = GetNewCode(); _databaseRepository.AddItem(context, sellerCode); propertyToUpsert = ConvertPropertyViewModelToDBType(viewModel, buyerCode.Id, sellerCode.Id); var defaultCheckListItems = _databaseRepository.GetDefaultCheckListItems(context); _databaseRepository.AddItem(context, propertyToUpsert); AddPropertyCheckListItem(context, propertyToUpsert.Id, defaultCheckListItems); } else { propertyToUpsert = ConvertPropertyViewModelToDBType(viewModel, viewModel.BuyerCodeId, viewModel.SellerCodeId); _databaseRepository.Update(context, propertyToUpsert, propertyToUpsert.Id); } return(true); } } catch (Exception ex) { _logger.ErrorFormat("Could not save the property with RMI: {0} \r\n Exception: {1}", viewModel.RightMoveIdentifier, ex.Message); return(false); } }
public bool Add(Feedback feedbackItem) { feedbackItem.AddedOn = _dateRepository.Now(); feedbackItem.Id = _guidRepository.NewGuid(); try { using (var context = new ChainsDBEntities()) { _databaseRepository.AddItem <Feedback>(context, feedbackItem); return(true); } } catch (Exception ex) { _logger.ErrorFormat("Could not save the feedback item. \r\nName: {0}\r\nEmail: {1}\r\nDetails: {2}\r\n\r\nException: {3}", feedbackItem.Name, feedbackItem.Email, feedbackItem.Details, ex.Message); return(false); } }