示例#1
0
        public ActionResult Create(LeadModel vm)
        {
            try
            {
                var newPerson = new Person
                {
                    Email     = vm.Email,
                    PhoneNo   = vm.Phone,
                    Country   = vm.Country,
                    FirstName = !string.IsNullOrEmpty(vm.FirstName) ? vm.FirstName : "Unknown",
                    LastName  = !string.IsNullOrEmpty(vm.LastName) ? vm.LastName : "Unknown"
                };

                _personRepository.Create(newPerson);

                var newCRMLead = new CRMLead
                {
                    Description      = vm.Message,
                    AssignedToUserId = vm.CreatedByUserId,
                    LeadSourceId     = vm.LeadSourceId,
                    CategoryId       = vm.CategoryId,
                    LeadStatusId     = vm.StatusId,
                    PersonId         = newPerson.Id,
                    RecievedOn       = DateTime.UtcNow,
                    CreatedByUserId  = vm.CreatedByUserId
                };

                _crmLeadRepository.Create(newCRMLead);
                _unitOfWork.Commit();

                var result = new ApiResult <bool>
                {
                    Status  = true,
                    Message = "Success"
                };

                return(Json(result));
            }
            catch (Exception ex)
            {
                var result = new ApiResult <bool>
                {
                    Status  = false,
                    Message = ex.Message
                };

                return(Json(result));
            }
        }
示例#2
0
        public ActionResult Create(NewCRMLeadViewModel vm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var newCRMLead = new CRMLead
                    {
                        AssignedToUserId = vm.AssignedToUserId,
                        LeadSourceId     = vm.LeadSourceId,
                        CategoryId       = vm.CategoryId,
                        LeadStatusId     = vm.LeadStatusId,
                        Person           = vm.Person,
                        Expertise        = vm.Expertise,
                        Description      = vm.Description,
                        RecievedOn       = vm.RecievedOn,
                        CreatedByUserId  = WebUser.Id
                    };

                    _crmLeadRepository.Create(newCRMLead);
                    _unitOfWork.Commit();

                    // Map the Technologies
                    if (vm.TechnologyIds != null)
                    {
                        foreach (var technologyId in vm.TechnologyIds)
                        {
                            var newMap = new CRMLeadTechnologyMap
                            {
                                LeadId       = newCRMLead.Id,
                                TechnologyId = technologyId
                            };

                            _crmLeadTechnologyMapRepository.Create(newMap);
                        }

                        _unitOfWork.Commit();
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Please fill all mandatory fields");
            }

            return(View(vm));
        }