public ActionResult AuditReasonSave(MODEL.AuditReason model)
        {
            try
            {
                bool ismodelValid = ModelState.IsValid;
                if (ismodelValid)
                {
                    //Get user id
                    int?userId = Session.GetUserId();
                    AuditReasonService auditReasonService = new AuditReasonService();
                    //AuditReasonVO auditReasonVO = new AuditReasonVO(model, userId);

                    AuditReasonVO auditReasonVO = model.Transpose(userId);

                    auditReasonService.SaveAuditReason(auditReasonVO);
                    return(new HttpStatusCodeResult(200));
                }
                else
                {
                    throw new ApplicationException(String.Format(Constants.CANNOT_SAVE, Constants.AUDIT_REASON));
                }
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeAndErrorResult(500, e.Message));
            }
        }
        /// <summary>
        /// Edit existing audit reason
        /// </summary>
        /// <param name="id">id</param>
        /// <returns></returns>
        public ActionResult AuditReasonEdit(int id)
        {
            MODEL.AuditReason auditReason = null;
            try
            {
                AuditReasonService auditReasonService = new AuditReasonService();

                //Get audit reason details
                AuditReasonVO auditReasonVO = auditReasonService.GetAuditReasonById(id);

                if (auditReasonVO == null)
                {
                    ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.AUDIT_REASON));
                }
                else
                {
                    auditReason = new AuditReason(auditReasonVO);
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }
            return(PartialView("AuditReasonDetails", auditReason));
        }
Exemple #3
0
        /// <summary>
        /// Save the AuditReason (new or edited)
        /// </summary>
        /// <param name="model">The Audit Reason Details (model)</param>
        /// <returns></returns>
        // POST: /Administration/AuditReasonSave
        public void SaveAuditReason(AuditReasonVO auditReasonVO)
        {
            AuditReason auditReason = null;

            if (auditReasonVO.ReasonCode == 0)
            {
                //create new audit reason
                auditReason = new AuditReason();
                auditReason.CreationDate = DateTime.Now;
                auditReason.CreatedBy    = auditReasonVO.CreatedByUserId;
            }
            else
            {
                //get audit reason for update
                auditReason = mdbDataContext.AuditReasons.SingleOrDefault(a => a.ReasonCode == auditReasonVO.ReasonCode);
                auditReason.LastUpdationDate = DateTime.Now;
                auditReason.LastUpdatedBy    = auditReasonVO.LastUpdatedByUserId;
            }

            //Create or update audit reason details
            auditReason.ReasonDescription = auditReasonVO.ReasonDescription;

            if (auditReasonVO.ReasonCode == 0)
            {
                //If new audit reason
                mdbDataContext.AuditReasons.InsertOnSubmit(auditReason);
            }

            mdbDataContext.SubmitChanges();
        }
Exemple #4
0
        /// <summary>
        /// Get the audit reason by name
        /// </summary>
        /// <returns></returns>
        public AuditReasonVO GetAuditReasonByName(string auditReasonDescription)
        {
            AuditReason   auditReason   = mdbDataContext.AuditReasons.Where(x => x.ReasonDescription == auditReasonDescription && x.IsDeleted == false).FirstOrDefault();
            AuditReasonVO auditReasonVO = null;

            if (auditReason != null)
            {
                auditReasonVO = new AuditReasonVO(auditReason);
            }
            return(auditReasonVO);
        }
        /// <summary>
        /// Transpose Model object to Value Object
        /// </summary>
        /// <param name="userId">user Id</param>
        /// <returns>Value object</returns>
        public AuditReasonVO Transpose(int?userId)
        {
            AuditReasonVO auditReasonVO = new AuditReasonVO();

            auditReasonVO.ReasonCode          = this.ID;
            auditReasonVO.ReasonDescription   = this.ReasonDescription;
            auditReasonVO.CreatedByUserId     = userId;
            auditReasonVO.LastUpdatedByUserId = userId;

            return(auditReasonVO);
        }
Exemple #6
0
        /// <summary>
        /// Get audit reason by id
        /// </summary>
        /// <param name="id">id</param>
        /// <returns></returns>
        public AuditReasonVO GetAuditReasonById(int id)
        {
            AuditReason auditReason = mdbDataContext.AuditReasons.SingleOrDefault(a => a.ReasonCode == id);

            AuditReasonVO auditReasonVO = null;

            if (auditReason != null)
            {
                auditReasonVO = new AuditReasonVO(auditReason);
            }
            return(auditReasonVO);
        }
Exemple #7
0
        /// <summary>
        /// Get the audit reason VO List
        /// </summary>
        /// <returns>Value object of audit reason List</returns>
        public List <AuditReasonVO> GetAuditReasonCodeVOList()
        {
            List <AuditReasonVO> auditReasonVOList = new List <AuditReasonVO>();
            List <AuditReason>   auditReasonList   = mdbDataContext.AuditReasons.Where(c => c.IsDeleted == false).OrderBy(c => c.ReasonCode).ToList();

            foreach (LINQ.AuditReason auditReason in auditReasonList)
            {
                AuditReasonVO auditReasonVO = new AuditReasonVO(auditReason);
                auditReasonVOList.Add(auditReasonVO);
            }

            return(auditReasonVOList);
        }
        /// <summary>
        /// Save the AuditReason (new or edited)
        /// </summary>
        /// <param name="model">The Audit Reason Details (model) and User Id</param>
        /// <returns></returns>
        // POST: /Administration/AuditReasonSave
        public void SaveAuditReason(AuditReasonVO auditReasonVO)
        {
            if (!String.IsNullOrEmpty(auditReasonVO.ReasonDescription))
            {
                AuditReasonVO auditReasonVOExist = auditReasonDAL.GetAuditReasonByName(auditReasonVO.ReasonDescription);

                //Check whether audit reason already exist or not
                if (auditReasonVOExist != null && auditReasonVOExist.ReasonCode != auditReasonVO.ReasonCode)
                {
                    throw new ApplicationException(Constants.AUDIT_REASON_ALREADY_EXISTS);
                }
                auditReasonDAL.SaveAuditReason(auditReasonVO);
            }
            else
            {
                throw new ApplicationException(Constants.AUDIT_REASON_CANNOT_BE_NULL);
            }
        }
 /// <summary>
 /// Constructor to transpose VO Object to model object
 /// </summary>
 /// <param name="auditReasonVO"></param>
 public AuditReason(AuditReasonVO auditReasonVO)
 {
     ReasonCode        = auditReasonVO.ReasonCode;
     ReasonDescription = auditReasonVO.ReasonDescription;
 }