public Cases CloseCases(int id) { var dbEntity = CrmDbContext.Cases.Find(id); if (dbEntity == null) { throw new ArgumentException(); } var entity = _mapper.Map <Cases>(dbEntity); if (dbEntity.IsClosed) { return(entity); } if (dbEntity.TenantId != TenantID) { return(null); } _crmSecurity.DemandEdit(entity); dbEntity.IsClosed = true; CrmDbContext.SaveChanges(); return(entity); }
public void EditDeal(Deal deal) { _crmSecurity.DemandEdit(deal); // var oldDeal = GetByID(deal.ID); // if (oldDeal.ContactID > 0) // RemoveMember(oldDeal.ID, oldDeal.ContactID); // AddMember(deal.ID, deal.ContactID); var itemToUpdate = CrmDbContext.Deals.Find(deal.ID); if (itemToUpdate.TenantId != TenantID) { throw new ArgumentException(); } itemToUpdate.Title = deal.Title; itemToUpdate.Description = deal.Description; itemToUpdate.ResponsibleId = deal.ResponsibleID; itemToUpdate.ContactId = deal.ContactID; itemToUpdate.BidCurrency = deal.BidCurrency; itemToUpdate.BidValue = deal.BidValue; itemToUpdate.BidType = deal.BidType; itemToUpdate.DealMilestoneId = deal.DealMilestoneID; itemToUpdate.DealMilestoneProbability = deal.DealMilestoneProbability; itemToUpdate.ExpectedCloseDate = deal.ExpectedCloseDate; itemToUpdate.PerPeriodValue = deal.PerPeriodValue; itemToUpdate.ActualCloseDate = _tenantUtil.DateTimeToUtc(deal.ActualCloseDate); itemToUpdate.LastModifedOn = _tenantUtil.DateTimeToUtc(_tenantUtil.DateTimeNow()); itemToUpdate.LastModifedBy = _securityContext.CurrentAccount.ID; CrmDbContext.SaveChanges(); _factoryIndexer.Index(itemToUpdate); }