コード例 #1
0
ファイル: MstReasonController.cs プロジェクト: donimuzur/fms
        public ActionResult Create()
        {
            var model = new ReasonItem();
            var list1 = _documentTypeBLL.GetDocumentType();

            var list2 = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "BENEFIT", Value = "BENEFIT"
                },
                new SelectListItem()
                {
                    Text = "WTC", Value = "WTC"
                }
            };

            model.DocumentTypeList = new SelectList(list1, "MstDocumentTypeId", "DocumentType");
            model.VehicleTypeList  = new SelectList(list2, "Text", "Value");
            model.MainMenu         = _mainMenu;
            model.CurrentLogin     = CurrentUser;
            return(View(model));
        }
コード例 #2
0
ファイル: MstReasonController.cs プロジェクト: donimuzur/fms
        public ActionResult Create(ReasonItem model)
        {
            if (ModelState.IsValid)
            {
                var dto = Mapper.Map <ReasonDto>(model);
                dto.CreatedBy   = CurrentUser.USER_ID;
                dto.CreatedDate = DateTime.Now;
                dto.IsActive    = true;
                try
                {
                    var exist = _rasonBLL.GetReason().Where(x => x.DocumentType == dto.DocumentType &&
                                                            (x.VehicleType == null ? "" : x.VehicleType.ToUpper()) == (dto.VehicleType == null ? "" : dto.VehicleType.ToUpper()) &&
                                                            (x.Reason == null ? "" : x.Reason) == (dto.Reason == null ? "" : dto.Reason.ToUpper())).FirstOrDefault();
                    if (exist != null)
                    {
                        model.ErrorMessage = "Data Already Exist in Master Reason";
                        var list1 = _documentTypeBLL.GetDocumentType();
                        var list2 = new List <SelectListItem>()
                        {
                            new SelectListItem()
                            {
                                Text = "BENEFIT", Value = "BENEFIT"
                            },
                            new SelectListItem()
                            {
                                Text = "WTC", Value = "WTC"
                            }
                        };

                        model.DocumentTypeList = new SelectList(list1, "MstDocumentTypeId", "DocumentType");
                        model.VehicleTypeList  = new SelectList(list2, "Text", "Value");
                        model.MainMenu         = _mainMenu;
                        model.CurrentLogin     = CurrentUser;
                        return(View(model));
                    }
                    _rasonBLL.save(dto);
                }
                catch (Exception ex)
                {
                    model.ErrorMessage = ex.Message;
                    var list1 = _documentTypeBLL.GetDocumentType();
                    var list2 = new List <SelectListItem>()
                    {
                        new SelectListItem()
                        {
                            Text = "BENEFIT", Value = "BENEFIT"
                        },
                        new SelectListItem()
                        {
                            Text = "WTC", Value = "WTC"
                        }
                    };
                    model.DocumentTypeList = new SelectList(list1, "MstDocumentTypeId", "DocumentType");
                    model.VehicleTypeList  = new SelectList(list2, "Text", "Value");
                    model.MainMenu         = _mainMenu;
                    model.CurrentLogin     = CurrentUser;
                    return(View(model));
                }
                _rasonBLL.SaveCanges();
            }

            return(RedirectToAction("Index", "MstReason"));
        }
コード例 #3
0
ファイル: MstReasonController.cs プロジェクト: donimuzur/fms
        public JsonResult UploadFile(HttpPostedFileBase upload)
        {
            var data  = (new ExcelReader()).ReadExcel(upload);
            var model = new List <ReasonItem>();

            if (data != null)
            {
                foreach (var dataRow in data.DataRows)
                {
                    if (dataRow[0] == "")
                    {
                        continue;
                    }
                    var item = new ReasonItem();
                    item.ErrorMessage = "";
                    try
                    {
                        var getdto = _documentTypeBLL.GetDocumentType().Where(x => x.DocumentType == dataRow[0]).FirstOrDefault();
                        item.MstDocumentType = dataRow[0];
                        if (getdto == null)
                        {
                            item.ErrorMessage = "Document " + dataRow[0] + " is not in the Master Document Type";
                        }
                        else if (getdto != null)
                        {
                            item.DocumentType = getdto.MstDocumentTypeId;
                        }

                        item.VehicleType = dataRow[1].ToUpper();
                        if (item.VehicleType == "")
                        {
                            item.ErrorMessage = "Vehicle Type Can't be empty";
                        }

                        item.Reason = dataRow[2].ToString();
                        if (item.Reason == "")
                        {
                            item.ErrorMessage = "Reason Can't be empty";
                        }

                        if (dataRow[3].ToString() == "Yes" | dataRow[3].ToString() == "YES" | dataRow[3].ToString() == "true" | dataRow[3].ToString() == "TRUE" | dataRow[3].ToString() == "1")
                        {
                            item.IsPenalty = true;
                        }
                        else if (dataRow[3].ToString() == "No" | dataRow[3].ToString() == "NO" | dataRow[3].ToString() == "False" | dataRow[3].ToString() == "FALSE" | dataRow[3].ToString() == "0")
                        {
                            item.IsPenalty = false;
                        }
                        else if (dataRow[3] == "")
                        {
                            item.ErrorMessage = "Penalty Can't be empty";
                        }

                        if (dataRow[4].ToString() == "Yes" | dataRow[4].ToString() == "YES" | dataRow[4].ToString() == "true" | dataRow[4].ToString() == "TRUE" | dataRow[4].ToString() == "1")
                        {
                            item.PenaltyForFleet = true;
                        }
                        else if (dataRow[4].ToString() == "No" | dataRow[4].ToString() == "NO" | dataRow[4].ToString() == "False" | dataRow[4].ToString() == "FALSE" | dataRow[4].ToString() == "0")
                        {
                            item.PenaltyForFleet = false;
                        }
                        if (dataRow[5].ToString() == "Yes" | dataRow[5].ToString() == "YES" | dataRow[5].ToString() == "true" | dataRow[5].ToString() == "TRUE" | dataRow[5].ToString() == "1")
                        {
                            item.PenaltyForEmplloyee = true;
                        }
                        else if (dataRow[5].ToString() == "No" | dataRow[5].ToString() == "NO" | dataRow[5].ToString() == "False" | dataRow[5].ToString() == "FALSE" | dataRow[5].ToString() == "0")
                        {
                            item.PenaltyForEmplloyee = false;
                        }

                        model.Add(item);
                    }
                    catch (Exception ex)
                    {
                        item.ErrorMessage = ex.Message;
                    }
                }
            }
            return(Json(model));
        }