Esempio n. 1
0
        public NotesDto CreateNote(NotesDto objNotesDto)
        {
            Notes objNotes = _mapper.Map <Notes>(objNotesDto);

            objNotes.CreatedDateTime = DateTime.Now;
            objNotes.CreatedBy       = 1;
            _context.Notes.Add(objNotes);
            _context.SaveChanges();

            return(_mapper.Map <NotesDto>(_context.Notes.
                                          SingleOrDefault(x => x.NotesId == objNotesDto.NotesId)));
        }
Esempio n. 2
0
        public ActivitiesDto CreateActivity(ActivitiesDto objActivitiesDto)
        {
            Activities objActivities = _mapper.Map <Activities>(objActivitiesDto);

            objActivities.CreatedDateTime = DateTime.Now;
            objActivities.CreatedBy       = 1;
            _context.Activities.Add(objActivities);
            _context.SaveChanges();

            return(_mapper.Map <ActivitiesDto>(_context.Activities.
                                               SingleOrDefault(x => x.ActivityId == objActivitiesDto.ActivityId)));
        }
Esempio n. 3
0
        public LeadDto CreateLead(LeadDto objLeadDto)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    Leads objLeads = _mapper.Map <Leads>(objLeadDto);
                    objLeads.CreatedDateTime = DateTime.Now;
                    objLeads.CreatedBy       = 1;
                    _context.Leads.Add(objLeads);
                    _context.SaveChanges();

                    foreach (var product in objLeadDto.ProductList)
                    {
                        ProductListDto objProductListDto = product;
                        ProductList    objProductList    = _mapper.Map <ProductList>(objProductListDto);
                        objProductList.ReferenceId     = objLeads.LeadId;
                        objProductList.Source          = 1;
                        objProductList.ProductId       = product.ProductId;
                        objProductList.CreatedBy       = 1;
                        objProductList.CreatedDateTime = DateTime.Now;
                        _context.ProductList.Add(objProductList);
                    }

                    foreach (var activity in objLeadDto.Activities)
                    {
                        ActivitiesDto objActivitiesDto = activity;
                        Activities    objActivities    = _mapper.Map <Activities>(objActivitiesDto);
                        objActivities.ReferenceId     = objLeads.LeadId;
                        objActivities.Source          = 1;
                        objActivities.CreatedBy       = 1;
                        objActivities.CreatedDateTime = DateTime.Now;
                        _context.Activities.Add(objActivities);
                    }

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