示例#1
0
        public ActionResult NewComplaint(NewComplaint model)
        {
            try
            {
                ViewBag.ComplaintType = _complaintType.GetAll();
                //ViewBag.SolutionType = _slnType.GetAll();
                //ViewBag.SolutionStatus = _slnStatus.GetAll();
                var user = _user.GetUser(User.Identity.Name);
                ViewBag.Complaints = _vComplaint.FilterComplaint(DateTime.Now.Date, DateTime.Now.Date, 0, 0, 0, user.UserId);

                if (ModelState.IsValid)
                {
                    if (model.Title.Trim().Contains(" "))
                    {
                        ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "Empty space is not allowed in Title, you can replace empty space with character like - or _");
                        return(View(model));
                    }
                    if (!string.IsNullOrEmpty(model.ComplaintOwnerEmail))
                    {
                        if (!_help.IsValidEmail(model.ComplaintOwnerEmail))
                        {
                            ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "Invalid email address!");
                            return(View(model));
                        }
                    }
                    if (!_help.IsValidPhone(model.MobileNo))
                    {
                        ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "Invalid phone number!");
                        return(View(model));
                    }
                    var compType = _complaintType.GetRecordById(model.ComplaintTypeId);
                    model.Title = compType.Name.Replace(" ", "_") + "_" + model.Title + "_" + model.MobileNo;
                    var cmp = _complaint.GetComplaintByTitle(model.Title);
                    if (cmp == null)
                    {
                        var soln = _slnStatus.GetRecordById(1);
                        if (soln.Name.ToUpper() == "RESOLVED FULLY")
                        {
                            model.StatusId = 4;
                        }
                        else
                        {
                            if (soln.Name.ToUpper() == "REQUIRED TECHNICAL SKILL")
                            {
                                model.StatusId = 3;
                            }
                            else
                            {
                                model.StatusId = 2;
                            }
                        }

                        Complaint nc = new Complaint();
                        nc.Code = model.Code;
                        nc.ComplaintOwnerEmail = null;
                        nc.ComplaintOwnerName  = null;
                        nc.ComplaintTypeId     = model.ComplaintTypeId;
                        nc.Date             = DateTime.Now;
                        nc.Details          = model.Details;
                        nc.Location         = model.Location;
                        nc.MobileNo         = model.MobileNo;
                        nc.RegisteredBy     = user.UserId;
                        nc.SolutionStatusId = 1;
                        nc.StatusId         = model.StatusId;
                        nc.Title            = model.Title;

                        using (var cmd = new TransactionScope())
                        {
                            try
                            {
                                _complaint.Create(nc);
                                //ComplaintActivity ca = new ComplaintActivity();
                                //ca.ComplaintId = nc.ComplaintId;
                                //ca.Date = DateTime.Now;
                                //ca.RecordedBy = user.UserId;
                                //ca.SolutionDetails = model.SolutionDetails;
                                //ca.SolutionStatusId = model.SolutionStatusId;
                                //ca.SolutionTypeId = model.SolutionTypeId;
                                //_complaintActivity.Create(ca);
                                cmd.Complete();
                                ViewBag.Msg = _help.getMsg(AlertType.success.ToString(), "Complaint added successful!");
                                return(View(new NewComplaint()));
                            }
                            catch (Exception er)
                            {
                                cmd.Dispose();
                                ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), er.Message);
                                return(View(model));
                            }
                        }
                    }
                    else
                    {
                        ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "Complaint title already exist!");
                        return(View(model));
                    }
                }
                else
                {
                    ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), "All fields with * are required!");
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Msg = _help.getMsg(AlertType.danger.ToString(), ex.Message);
                return(View(model));
            }
        }