예제 #1
0
        public async Task<JsonResult> NewRequest(string btnSubmit, FARRequestViewModel viewmodel)
        {
            if (!ModelState.IsValid)
            {
                var bind = await BindRequestDashboard();
                bind.BUId = viewmodel.BUId;
                bind.OriginId = viewmodel.OriginId;
                bind.FailureTypeId = viewmodel.FailureTypeId;
                bind.StatusId = viewmodel.StatusId;
                bind.PriorityId = viewmodel.PriorityId;
                bind.LabSiteId = viewmodel.LabSiteId;
                Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "invalidate" }
                };
            }

            string suffix = (await OriginRepository.SingleAsync(viewmodel.OriginId)).Name;
            var newFARNumber = GeneralFARNumber(suffix);
            bool isSubmit = false;
            switch (btnSubmit)
            {
                case "Save":
                    isSubmit = false;
                    break;
                case "Submit":
                    isSubmit = true;
                    break;
            }
            FARMasterDto master = new FARMasterDto()
            {
                Number = newFARNumber,
                OriginId = viewmodel.OriginId,
                Requestor = viewmodel.Requestor,
                RefNo = viewmodel.RefNo,
                FailureTypeId = viewmodel.FailureTypeId,
                FailureOriginId = viewmodel.FailureOriginId,
                FailureRate = viewmodel.FailureRate,
                StatusId = (int)StatusType.OPEN,
                LabSiteId = viewmodel.LabSiteId,
                RequestDate = viewmodel.RequestDate,
                SamplesArriveDate = viewmodel.SamplesArriveDate,
                PriorityId = viewmodel.PriorityId,
                BUId = viewmodel.BUId,
                Product = viewmodel.Product,
                FailureDesc = viewmodel.FailureDesc,
                Customer = viewmodel.Customer,
                LastUpdatedBy = this.CurrentName,
                Submitted = isSubmit,

                //Enhancement
                Comments = String.Empty
            };

            //Enhancement
            if (!String.IsNullOrEmpty(viewmodel.Product))
            {
                try
                {
                    //var products = ProductRepository.FindByName(viewmodel.Product);
                    //Enhacement https://mail.google.com/mail/u/0/?tab=wm#inbox/1549ffc4556acdc7
                    var products = ProductRepository.FindByNameAndLabSite(viewmodel.Product, viewmodel.LabSiteId);
                    if (products != null && products.Count() > 0)
                    {
                        var product = products.First();
                        if (!String.IsNullOrEmpty(product.MainPerson))
                            master.Analyst = product.MainPerson;
                        else
                            if (!String.IsNullOrEmpty(product.SecondaryPerson))
                                master.Analyst = product.SecondaryPerson;
                            else
                                if (!String.IsNullOrEmpty(product.TertiaryPerson))
                                    master.Analyst = product.TertiaryPerson;
                    }
                }
                catch (Exception ex)
                {
                    LogService.Error(ex.Message, ex);
                }
            }
            //End Enhancement #18

            var result = await MasterRepository.AddMasterAsync(master);
            if (result > 0)
            {

                if (!String.IsNullOrEmpty(master.Analyst))
                {
                    //SendMail
                    string emailSubject = "FA Request " + master.Number + " has been assigned to you";
                    string ebody = "You have been assigned by " + this.CurrentName + " to oversee FA Number: " + master.Number + ". Please login to FA DB to update its details.";
                    string emailBody = string.Format("{0}<br><br>{1}", ebody, DateTime.Now.ToShortDateString());
                    Mail.Send(master.Analyst, emailSubject, ebody);
                }

                //Copy all files temp tp folder id master, and remove all file temp
                string filesTemp = System.IO.Path.Combine(Server.MapPath("~/Upload/Temp"), viewmodel.Gu);
                if (System.IO.Directory.Exists(filesTemp))
                {
                    //get all files
                    string[] files = System.IO.Directory.GetFiles(filesTemp);
                    string folderMaster = System.IO.Path.Combine(Server.MapPath("~/Upload"), result.ToString().PadLeft(10, '0'));
                    if (!System.IO.Directory.Exists(folderMaster))
                        System.IO.Directory.CreateDirectory(folderMaster);

                    foreach (string file in files)
                    {
                        System.IO.File.Copy(file, System.IO.Path.Combine(folderMaster, System.IO.Path.GetFileName(file)));
                        System.IO.File.Delete(file);
                    }

                    //Remove all file temp
                    System.IO.Directory.Delete(filesTemp);
                }
                Response.StatusCode = (int)HttpStatusCode.OK;
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { code = result }
                };
            }
            else
            {
                var bind = await BindRequestDashboard();
                bind.BUId = viewmodel.BUId;
                bind.OriginId = viewmodel.OriginId;
                bind.FailureTypeId = viewmodel.FailureTypeId;
                bind.StatusId = viewmodel.StatusId;
                bind.PriorityId = viewmodel.PriorityId;
                bind.LabSiteId = viewmodel.LabSiteId;

                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "Failure" }
                };
            }
        }
예제 #2
0
        /// <summary>
        /// Binds the request dashboard.
        /// </summary>
        /// <returns></returns>
        private async Task<FARRequestViewModel> BindRequestDashboard()
        {
            var reqOrigin = await OriginRepository.GetAllAsync();
            var reqStat = (await StatusRepository.GetAllAsync()).Where(w => w.Id == (int)StatusType.OPEN);
            var reqBu = await BuRepository.GetAllAsync();
            var reqFailType = await FailureTypeRepository.GetAllAsync();
            var reqProdLine = await ProductRepository.GetAllAsync();
            var reqFailureOrigin = await FailureOriginRepository.GetAllAsync();
            var reqPriority = await PriorityRepository.GetAllAsync();
            var labsites = await LabSiteRepository.GetAllAsync();
            var requestor = this.CurrentName;
            var requestorSite = this.Site;

            FARRequestViewModel bind = new FARRequestViewModel
            {
                Origins = reqOrigin,
                Status = reqStat,
                BUs = reqBu,
                FailureTypes = reqFailType,
                FailureOrigins = reqFailureOrigin,
                Priorities = reqPriority,
                Requestor = requestor,
                Site = requestorSite,
                LabSites = labsites
            };

            return bind;
        }