public PublicComplaintActionViewModel(ComplaintAction e)
 {
     ComplaintId = e.ComplaintId;
     ActionDate  = e.ActionDate;
     ActionType  = e.ActionType;
     Comments    = e.Comments;
 }
Beispiel #2
0
        public string SaveAction(ComplaintAction obj)
        {
            try {
                int            usersno    = (((CargoFlash.Cargo.Model.UserLogin)(System.Web.HttpContext.Current.Session["UserDetail"]))).UserSNo;
                DataSet        ds         = new DataSet();
                SqlParameter[] Parameters =
                {
                    new SqlParameter("@ComplaintActionSNo",       obj.ComplaintActionSNo),
                    new SqlParameter("@ActionDate",               obj.ActionDate),
                    new SqlParameter("@ActionDescription",        obj.ActionDescription),
                    new SqlParameter("@IsNotify",                 obj.IsNotify),
                    new SqlParameter("@EmailID",                  obj.EmailId),
                    new SqlParameter("@ComplaintActionStatusSNo", obj.ComplaintActionStatusSNo),
                    new SqlParameter("@ComplaintSNo",             obj.ComplaintSNo),
                    new SqlParameter("@UserSno",                  usersno)
                };


                ds = SqlHelper.ExecuteDataset(DMLConnectionString.WebConfigConnectionString, CommandType.StoredProcedure, "SaveComplaintAction", Parameters);
                return(ds.Tables[ds.Tables.Count - 1].Rows[0][0].ToString());
            }
            catch (Exception ex)//(Exception ex)
            {
                throw ex;
            }
        }
 public ComplaintActionsListViewModel(ComplaintAction i)
 {
     if (i != null)
     {
         Id           = i.Id;
         ComplaintId  = i.ComplaintId;
         ActionDate   = i.ActionDate;
         ActionType   = i.ActionType;
         Investigator = i.Investigator;
         EnteredBy    = i.EnteredBy;
         Comments     = (i.Comments == null) ? null : i.Comments.Substring(0, Math.Min(100, i.Comments.Length)) + (i.Comments.Length > 100 ? "…" : string.Empty);
         Deleted      = i.Deleted;
     }
 }
Beispiel #4
0
        public async Task <IActionResult> AddAction(int id, AddComplaintActionViewModel model)
        {
            var currentUser = await GetCurrentUserAsync();

            if (currentUser == null)
            {
                throw new Exception("Current user not found");
            }

            string msg;

            var complaint = await _context.Complaints.AsNoTracking()
                            .Where(e => e.Id == model.ComplaintId)
                            .SingleOrDefaultAsync();

            if (complaint == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var complaintAction = new ComplaintAction(model);

                // Check permissions
                if (complaint.Deleted)
                {
                    msg = "This Complaint has been deleted and cannot be edited.";
                    TempData.SaveAlertForSession(msg, AlertStatus.Warning, "Access Denied");
                    return(RedirectToAction("Details", new { id = model.ComplaintId }));
                }
                if (currentUser.Id != complaint.CurrentOwnerId &&
                    !(User.IsInRole(CtsRole.Manager.ToString()) && currentUser.OfficeId == complaint.CurrentOfficeId) &&
                    !(User.IsInRole(CtsRole.DivisionManager.ToString())))
                {
                    msg = "You do not have permission to edit this Complaint.";
                    TempData.SaveAlertForSession(msg, AlertStatus.Warning, "Access Denied");
                    return(RedirectToAction("Details", new { id = model.ComplaintId }));
                }
                if (currentUser != null &&
                    (currentUser.Id == complaint.CurrentOwnerId) &&
                    (complaint.DateCurrentOwnerAccepted == null))
                {
                    msg = "You must accept this Complaint before you can edit it.";
                    TempData.SaveAlertForSession(msg, AlertStatus.Warning, "Access Denied");
                    return(RedirectToAction("Details", new { id = model.ComplaintId }));
                }
                if (complaint.ComplaintClosed)
                {
                    msg = "This Complaint has been closed and cannot be edited unless it is reopened.";
                    TempData.SaveAlertForSession(msg, AlertStatus.Warning, "Access Denied");
                    return(RedirectToAction("Details", new { id = model.ComplaintId }));
                }

                // Update model
                complaintAction.EnteredById = currentUser.Id;
                complaintAction.DateEntered = DateTime.Now;

                try
                {
                    _context.Add(complaintAction);
                    await _context.SaveChangesAsync();

                    msg = "The Action has been added.";
                    TempData.SaveAlertForSession(msg, AlertStatus.Success, "Success");

                    return(RedirectToAction("Actions", new { id = model.ComplaintId }));
                }
                catch
                {
                    msg = "There was an error saving the Action. Please try again or contact support.";
                    ViewData["AlertMessage"] = new AlertViewModel(msg, AlertStatus.Error, "Error");
                }
            }

            msg = "The Action was not created. Please fix the errors shown below.";
            ViewData["AlertMessage"] = new AlertViewModel(msg, AlertStatus.Error, "Error");

            // Populate the view model before returning
            var vm = new ViewComplaintActionsViewModel(complaint, model);

            if (vm == null)
            {
                return(NotFound());
            }

            bool includeDeleted = User != null &&
                                  (User.IsInRole(CtsRole.DivisionManager.ToString()) ||
                                   User.IsInRole(CtsRole.Manager.ToString()));

            vm.ComplaintActions = await _dal.GetComplaintActionsByComplaintId(model.ComplaintId, SortOrder.Descending, includeDeleted).ToListAsync();

            vm.ActionTypesSelectList = await _dal.GetActionTypesSelectListAsync();

            vm.UserCanDelete = includeDeleted;
            return(View("Actions", vm));
        }