public ActionResult Create(DecisionViewModel model) { try { if (ModelState.IsValid) { var f = Request.Files["Document"]; if (f != null && f.ContentLength > 0) { string pic = System.IO.Path.GetFileName(f.FileName);//System.IO.Path.GetFileName(f.FileName); var avatarpath = "/Uploads/Lichsuquyetdinhs"; string path = System.IO.Path.Combine(Server.MapPath(avatarpath), pic); // file is uploaded f.SaveAs(path); using (MemoryStream ms = new MemoryStream()) { f.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); } model.Document = string.Join("/", avatarpath, pic); } service.Insert(model); service.Save(); return(RedirectToAction("Index", "Decision", new { employeeId = model.EmployeeId })); } var employees = employee.GetEmployeeSelectListItems().Select(x => new { Id = x.Id, Name = x.Id + " - " + x.FirstName + " " + x.LastName }).ToList(); ViewBag.Employees = new SelectList(employees, "Id", "Name"); var decisiontypes = _decisiontypeService.GetDecisionTypes(); ViewBag.DecisionTypes = new SelectList(decisiontypes, "Id", "Name"); return(View(model)); } catch (Exception e) { return(View(model)); } }
public ActionResult EditDecision(DecisionModels model) { if (model.id <= 0) { throw new HttpRequestValidationException(); } IDecisionService decSrc = IoC.Resolve <IDecisionService>(); try { Decision oDec = model.UpdateDecision(new Decision()); //lấy thông tin về mẫu hóa đơn IList <Pupor> lstp = (IList <Pupor>)model.DecDatasource.DeserializeJSON <Pupor>(typeof(IList <Pupor>)); string json = "<Root>"; string lstPattern = ""; foreach (Pupor p in lstp) { json += "<Purpose>" + p.Mucdich + "</Purpose>"; lstPattern += p.InvPattern + ','; } json += "</Root>"; lstPattern = lstPattern.Remove(lstPattern.Length - 1, 1); oDec.ListInvPattern = lstPattern; oDec.Purpose = json; //end //oDec.EffectiveDate = DateTime.ParseExact(Request["EffectiveDate"], "dd/MM/yyyy", null); decSrc.Save(oDec); decSrc.CommitChanges(); Messages.AddFlashMessage(Resources.Message.Dec_UMesSuccess); log.Info("EditDecision by: " + HttpContext.User.Identity.Name); return(RedirectToAction("ListDecision")); } catch (HttpRequestValidationException ex) { return(Redirect("/Home/PotentiallyError")); } catch (ArgumentException ex) { return(Redirect("/Home/PotentiallyError")); } catch (Exception ex) { ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "InvPattern", "InvPattern"); Messages.AddErrorMessage(Resources.Message.Dec_UMesUnsuccess); log.Error(" EditDecision -" + ex.Message); return(View(model)); } }