public JsonResult Index(FARReportGeneratorViewModel model)
        {
            string folderTop = Server.MapPath("~");
            string folderMaster = Path.Combine(folderTop, "Upload", model.Id.ToString().PadLeft(10, '0'));
            string folderDevice = Path.Combine(folderMaster, "DEVICE");

            string folderDeviceDetail = String.Empty;
            string folderProcess = String.Empty;

            var dataSource = new FARReportGeneratorViewModel();
            //find user1
            var user1 = UsersRes.CheckExistEmail(this.CurrentName);
            //find user2
            var user2 = UsersRes.CheckExistEmail(model.Analyst);
            //find user3
            var user3 = UsersRes.CheckExistEmail(model.Analyst);
            //ProcessTypes
            var processTypes = ProcessTypeRep.GetAll().ToList();
            //Requestor
            var requestor = UsersRes.CheckExistEmail(model.Requestor);

            foreach (var device in model.DeviceDetails)
            {
                var deviceEnity = DeviceDetailsRepository.Single(device.Id);
                dataSource.DeviceDetails.Add(deviceEnity);

                folderDeviceDetail = Path.Combine(folderDevice, device.Id.ToString().PadLeft(10, '0'));
                foreach (var pro in device.ProcessHis)
                {
                    folderProcess = Path.Combine(folderDeviceDetail, pro.Id.ToString().PadLeft(10, '0'));
                    if (pro.IsSelected)
                    {
                        //if (!String.IsNullOrEmpty(pro.SelectPhoto) && pro.SelectPhoto.Equals("Yes"))
                        //{
                        var proHis = ProcessHisRep.Single(pro.Id);
                        proHis.SelectPhoto = pro.SelectPhoto;
                        //Get all files in folder Process
                        if (Directory.Exists(folderProcess))
                        {
                            string[] files = Directory.GetFiles(folderProcess);
                            if (files != null && files.Count() > 0)
                            {
                                proHis.Photos.AddRange(files);
                            }
                        }
                        deviceEnity.ProcessHis.Add(proHis);
                        //}

                    }
                }
            }

            FASTrack.Infrastructure.FastrackWord word = new Infrastructure.FastrackWord(folderTop);
            word.DataSource = dataSource;
            word.User1 = user1;
            word.User2 = user2;
            word.User3 = user3;
            word.Requestor = requestor;
            word.ProcessTypes = processTypes;

            string file = word.Execute();

            if (String.IsNullOrEmpty(file))
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return new JsonResult
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { code = "EX02", path = String.Empty }
                };
            }

            Response.StatusCode = (int)HttpStatusCode.OK;
            return new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new { code = "EX01", path = file }
            };
        }
        private async Task<FARReportGeneratorViewModel> BindReport(int masterId)
        {
            FARReportGeneratorViewModel farRequest = new FARReportGeneratorViewModel();

            var master = await MasterRepository.SingleAsync(masterId);

            if (master != null)
            {
                farRequest.Analyst = master.Analyst;
                //farRequest.BUId = master.BUId;
                farRequest.BU = master.Bu;
                farRequest.FARNumber = master.Number;
                farRequest.FailureDesc = master.FailureDesc;
                //farRequest.FailureOriginId = master.FailureOriginId;
                farRequest.FailureOrigin = master.FARFailureOrigin;
                farRequest.FailureRate = master.FailureRate;
                //farRequest.FailureTypeId = master.FailureTypeId;
                farRequest.FailureType = master.FARFailureType;
                farRequest.Id = masterId;
                farRequest.InitialReportTargetDate = master.InitialReportTargetDate;
                farRequest.FinalReportTargetDate = master.FinalReportTargetDate;

                farRequest.Origin = master.FAROrigin;
                //farRequest.OriginId = master.OriginId;
                farRequest.Priority = master.FARPriority;
                //farRequest.PriorityId = master.PriorityId;
                farRequest.Product = master.Product;
                farRequest.RefNo = master.RefNo;
                farRequest.RequestDate = master.RequestDate;
                farRequest.Requestor = master.Requestor;
                farRequest.SamplesArriveDate = master.SamplesArriveDate;
                farRequest.StatusId = master.StatusId;
                farRequest.State = master.FARStatus;
                farRequest.Customer = master.Customer;
                //farRequest.LabSiteId = master.LabSiteId;
                farRequest.LabSite = master.LabSite;
                farRequest.Submitted = master.Submitted;
                farRequest.Site = this.Site;
                farRequest.LastUpdate = master.LastUpdate;
            }

            //farRequest.Origins = await OriginRepository.GetAllAsync();
            farRequest.Status = await StatusRepository.GetAllAsync();
            //farRequest.BUs = await BuRepository.GetAllAsync();
            //farRequest.FailureTypes = await FailureTypeRepository.GetAllAsync();
            //farRequest.FailureOrigins = await FailureOriginRepository.GetAllAsync();
            //farRequest.Priorities = await PriorityRepository.GetAllAsync();
            //farRequest.ReasonClose = await ReasonFARCloseRepository.GetAllAsync();
            //farRequest.LabSites = await LabSiteRepository.GetAllAsync();
            //farRequest.Rates = await RatingRep.GetAllAsync();

            return farRequest;
        }