Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToInt32(ddlCompany.SelectedValue) <= 0)
                {
                    MessageBox.Show("Please select company ", "Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (string.IsNullOrEmpty(txtLocation.Text))
                {
                    MessageBox.Show("Please enter location", "Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (Convert.ToInt32(ddlPriority.SelectedValue) <= -1)
                {
                    MessageBox.Show("Please select priority ", "Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (Convert.ToInt32(ddlComplexity.SelectedValue) <= -1)
                {
                    MessageBox.Show("Please select complexity ", "Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (Convert.ToInt32(ddlAssignedTo.SelectedValue) <= 0)
                {
                    MessageBox.Show("Please select engineer ", "Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var imageLibrary = new FaultLibrary();

                var fault = new Fault();
                fault.CreatedDate        = DateTime.Now;
                fault.CreatedBy          = AuthenticatedDetails.LoggedUser.Id;
                fault.Status             = 1;
                fault.CompanyId          = Convert.ToInt32(ddlCompany.SelectedValue);
                fault.Complexity         = Convert.ToInt32(ddlComplexity.SelectedValue);
                fault.FaultDescription   = txtFaultDescription.Text;
                fault.FaultStatus        = Convert.ToInt32(ddlPriority.SelectedValue) < 1 ? 0 : 1;
                fault.Location           = txtLocation.Text;
                fault.MachineDescription = txtMachineDescription.Text;
                fault.ModifiedBy         = AuthenticatedDetails.LoggedUser.Id;
                fault.ModifiedDate       = DateTime.Now;
                fault.Priority           = Convert.ToInt32(ddlPriority.SelectedValue);
                fault.StartDate          = DateTime.Now;
                fault.AssignedTo         = Convert.ToInt32(ddlAssignedTo.SelectedValue);
                fault.FaultLibraries     = new List <FaultLibrary>();

                FaultRepository.SaveFault(fault);
                MessageBox.Show("Job Added Successfully !!!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                _parent.ViewJobs();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to load form", "Error !!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        public ActionResult Add(FaultDTO model, HttpPostedFileBase postedfile)
        {
            ViewBag.Priorities   = FaultPrioritiesRepository.GetActivePriorities();
            ViewBag.Complexities = FaultComplexityRepository.GetActiveComplexities();
            ViewBag.Companies    = CompanyRepository.GetAllActive();
            ViewBag.Enigineers   = UsersinfoRepository.GetAllActiveEngineers();
            try
            {
                if (model.CompanyId == null || model.CompanyId <= 0)
                {
                    ViewBag.Message = "Please select company";
                    ViewBag.IsError = true;
                    return(View(model));
                }
                if (string.IsNullOrEmpty(model.Location))
                {
                    ViewBag.Message = "Please enter location name";
                    ViewBag.IsError = true;
                    return(View(model));
                }
                if (model.Priority == null)
                {
                    ViewBag.Message = "Please select priority";
                    ViewBag.IsError = true;
                    return(View(model));
                }
                if (model.Complexity == null)
                {
                    ViewBag.Message = "Please select complexity";
                    ViewBag.IsError = true;
                    return(View(model));
                }
                if (model.AssignedTo == null || model.AssignedTo <= 0)
                {
                    ViewBag.Message = "Please select an engineer";
                    ViewBag.IsError = true;
                    return(View(model));
                }
                var imageLibrary = new FaultLibrary();
                if (postedfile != null)
                {
                    var filePath = SaveImage(postedfile);
                    imageLibrary.FileName     = postedfile.FileName;
                    imageLibrary.Url          = filePath;
                    imageLibrary.ModifiedBy   = this.CurrentSession.LoggedUser.Id;
                    imageLibrary.ModifiedDate = DateTime.Now;
                    imageLibrary.CreatedDate  = DateTime.Now;
                    imageLibrary.CreatedBy    = this.CurrentSession.LoggedUser.Id;
                }
                var fault = new Fault()
                {
                    CompanyId          = model.CompanyId,
                    CreatedDate        = DateTime.Now,
                    CreatedBy          = this.CurrentSession.LoggedUser.Id,
                    Complexity         = model.Complexity,
                    FaultDescription   = model.FaultDescription,
                    FaultStatus        = model.Priority < 1 ? 0 : 1,
                    Location           = model.Location,
                    MachineDescription = model.MachineDescription,
                    ModifiedBy         = this.CurrentSession.LoggedUser.Id,
                    ModifiedDate       = DateTime.Now,
                    Priority           = model.Priority,
                    StartDate          = DateTime.Now,
                    Status             = 1,
                    AssignedTo         = model.AssignedTo,
                    FaultLibraries     = new List <FaultLibrary>()
                };
                if (!string.IsNullOrEmpty(imageLibrary.Url))
                {
                    imageLibrary.FaultId = fault.Id;
                    fault.FaultLibraries.Add(imageLibrary);
                }

                FaultRepository.SaveFault(fault);
                TempData["Message"] = "Job added successfully !!!";
                TempData["IsError"] = false;
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Failed to save job details";
                ViewBag.IsError = true;
            }
            return(View(model));
        }