예제 #1
0
        public NotesDto UpdateNote(NotesDto objNotesDto)
        {
            Notes objNotes     = _mapper.Map <Notes>(objNotesDto);
            Notes objNotesData = _context.Notes.Find(objNotesDto.NotesId);

            objNotes.ModifiedDateTime = DateTime.Now;
            objNotes.ModifiedBy       = 1;
            _context.Entry(objNotesData).CurrentValues.SetValues(objNotes);
            _context.SaveChanges();
            return(_mapper.Map <NotesDto>(_context.Notes.
                                          SingleOrDefault(x => x.NotesId == objNotesDto.NotesId)));
        }
예제 #2
0
        public ActivitiesDto UpdateActivity(ActivitiesDto objActivitiesDto)
        {
            Activities objActivities     = _mapper.Map <Activities>(objActivitiesDto);
            Activities objActivitiesData = _context.Activities.Find(objActivitiesDto.ActivityId);

            objActivities.ModifiedDateTime = DateTime.Now;
            objActivities.ModifiedBy       = 1;
            _context.Entry(objActivitiesData).CurrentValues.SetValues(objActivities);
            _context.SaveChanges();
            return(_mapper.Map <ActivitiesDto>(_context.Activities.
                                               SingleOrDefault(x => x.ActivityId == objActivitiesDto.ActivityId)));
        }
예제 #3
0
        public LeadDto UpdateLead(LeadDto objLeadDto)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    Leads objLeads     = _mapper.Map <Leads>(objLeadDto);
                    Leads objLeadsData = _context.Leads.Find(objLeadDto.LeadId);
                    objLeads.ModifiedDateTime = DateTime.Now;
                    objLeads.ModifiedBy       = 1;
                    _context.Entry(objLeadsData).CurrentValues.SetValues(objLeads);

                    #region productlist update

                    foreach (var product in objLeadDto.ProductList)
                    {
                        if (product.ProductListId == 0)
                        {
                            ProductListDto objProductListDto = product;
                            ProductList    objProductList    = _mapper.Map <ProductList>(objProductListDto);
                            objProductList.ReferenceId     = objLeadDto.LeadId;
                            objProductList.Source          = 1;
                            objProductList.ProductId       = product.ProductId;
                            objProductList.CreatedBy       = 1;
                            objProductList.CreatedDateTime = DateTime.Now;
                            _context.ProductList.Add(objProductList);
                        }
                        else
                        {
                            ProductList    objProductListdata = _context.ProductList.Find(product.ProductListId);
                            ProductListDto objProductListDto  = product;
                            ProductList    objProductList     = _mapper.Map <ProductList>(objProductListDto);
                            objProductList.ModifiedBy       = 1;
                            objProductList.ModifiedDateTime = DateTime.Now;
                            _context.Entry(objProductListdata).CurrentValues.SetValues(objProductList);
                        }
                    }
                    #endregion

                    #region activities update

                    foreach (var activities in objLeadDto.Activities)
                    {
                        if (activities.ActivityId == 0)
                        {
                            ActivitiesDto objActivitiesDto = activities;
                            Activities    objActivities    = _mapper.Map <Activities>(objActivitiesDto);
                            objActivities.ReferenceId     = objLeadDto.LeadId;
                            objActivities.Source          = 1;
                            objActivities.CreatedBy       = 1;
                            objActivities.CreatedDateTime = DateTime.Now;
                            _context.Activities.Add(objActivities);
                        }
                        else
                        {
                            Activities    objActivitiesdata = _context.Activities.Find(activities.ActivityId);
                            ActivitiesDto objActivitiesDto  = activities;
                            Activities    objActivities     = _mapper.Map <Activities>(objActivitiesDto);
                            objActivities.ModifiedBy       = 1;
                            objActivities.ModifiedDateTime = DateTime.Now;
                            _context.Entry(objActivitiesdata).CurrentValues.SetValues(objActivities);
                        }
                    }
                    #endregion

                    _context.SaveChanges();
                    transaction.Commit();
                    return(_mapper.Map <LeadDto>(_context.Leads.
                                                 SingleOrDefault(x => x.LeadId == objLeadDto.LeadId)));
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }