public PostsController(BlogContext db, IHostEnvironment environment, UploadFileService uploadFileService, UserManager <User> userManager) { _db = db; _environment = environment; _uploadFileService = uploadFileService; _userManager = userManager; }
public TrainersController(IWebHostEnvironment appEnvironment, DataManager dataManager, UploadFileService uploadFileService) { _appEnvironment = appEnvironment; _dataManager = dataManager; _uploadFileService = uploadFileService; }
public void Can_mock_uploading_files() { using (new BasicAppHost { ConfigureAppHost = host => host.VirtualFiles = new InMemoryVirtualPathProvider(host), }.Init()) { var ms = new MemoryStream("mocked".ToUtf8Bytes()); var httpFile = new HttpFile { ContentType = "application/x-msaccess", FileName = "C:\\path\\to\\file.txt", InputStream = ms, ContentLength = ms.ToArray().Length, }; var mockReq = new MockHttpRequest { Files = new IHttpFile[] { httpFile }, }; //Mock Session mockReq.Items[Keywords.Session] = new AuthUserSession { Id = "sess-id" }; var service = new UploadFileService { Request = mockReq }; service.Any(new MockUploadFile()); var files = HostContext.VirtualFiles.GetAllFiles().ToList(); Assert.That(files[0].ReadAllText(), Is.EqualTo("mocked")); } }
public void Can_mock_uploading_files() { using (new BasicAppHost { ConfigureAppHost = host => host.VirtualFiles = new MemoryVirtualFiles(), }.Init()) { var ms = new MemoryStream("mocked".ToUtf8Bytes()); var httpFile = new HttpFile { ContentType = "application/x-msaccess", FileName = "C:\\path\\to\\file.txt", InputStream = ms, ContentLength = ms.ToArray().Length, }; var mockReq = new MockHttpRequest { Files = new IHttpFile[] { httpFile }, }; //Mock Session mockReq.Items[Keywords.Session] = new AuthUserSession { Id = "sess-id" }; var service = new UploadFileService { Request = mockReq }; service.Any(new MockUploadFile()); var files = HostContext.VirtualFiles.GetAllFiles().ToList(); Assert.That(files[0].ReadAllText(), Is.EqualTo("mocked")); } }
public ActionResult Add_Post() { string filename = Request.Form["Image"]; string src = Request.Form["src"]; if (UploadFileService.UploadFileToServerBase64(filename, Constants.MAINBOARD_PATH, src)) { var mainboard = _MainboardService.CreateMainboard(); try { mainboard.Name = Request.Form["Name"]; } catch (Exception e) { } try { mainboard.Description = Request.Form["Description"]; } catch (Exception e) { } try { mainboard.TradeMark = Request.Form["TradeMark"]; } catch (Exception e) { } try { mainboard.Type = Request.Form["Type"]; } catch (Exception e) { } try { mainboard.Model = Request.Form["Model"]; } catch (Exception e) { } try { mainboard.Chipset = Request.Form["Chipset"]; } catch (Exception e) { } try { mainboard.MaxRamMemory = Request.Form["MaxRamMemory"]; } catch (Exception e) { } try { mainboard.RamType = Request.Form["RamType"]; } catch (Exception e) { } try { mainboard.HDMINum = Request.Form["HDMINum"]; } catch (Exception e) { } try { mainboard.Price = Request.Form["Price"]; } catch (Exception e) { } try { mainboard.RamNum = Int32.Parse(Request.Form["RamNum"]); } catch (Exception e) { } try { mainboard.WarrantyPeriod = Int32.Parse(Request.Form["WarrantyPeriod"]); } catch (Exception e) { } mainboard.IsDeleted = false; mainboard.Image = filename; int num = 0; string price = mainboard.Price.Replace(".", "").Replace("đ", ""); if (int.TryParse(price, out num) == false) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Giá phải nhập số</p>"; return(RedirectToAction("Add")); } else { if (num < 0) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Nhập giá lớn hơn 0</p>"; return(RedirectToAction("Add")); } } if (_MainboardService.InsertMainboard(mainboard)) { Session["submit_message"] = null; return(RedirectToAction("Index")); } else { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #dd0808!important;font-weight: bold;'>Add keyboard failed</p>"; return(View()); } } else { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #dd0808!important;font-weight: bold;'>Add keyboard failed</p>"; return(View()); } }
public ActionResult UploadFile() { string filename = string.Empty; //HttpPostedFileBase uploadFile = Request.Files["uploadFile"] as HttpPostedFileBase; string path = AppSetting.GetFileUploadTempPath; bool result = UploadFileService.UploadFile(/*uploadFile,*/ path, out filename); return(Json(new { result = result, filename = filename })); }
public ActionResult Add_Post() { try { // upload image of computer string filename = Request.Form["Image"]; string src = Request.Form["src"]; if (UploadFileService.UploadFileToServerBase64(filename, Constants.RAM_PATH, src)) { var ram = _RAMService.CreateRAM(); #region get properties try { ram.Name = Request.Form["Name"]; } catch (Exception e) { } try { ram.Description = Request.Form["Description"]; } catch (Exception e) { } try { ram.TradeMark = Request.Form["TradeMark"]; } catch (Exception e) { } try { ram.Color = Request.Form["Color"]; } catch (Exception e) { } try { ram.RamType = Request.Form["RamType"]; } catch (Exception e) { } try { ram.Memory = Request.Form["Memory"]; } catch (Exception e) { } try { ram.BusSpeed = Request.Form["BusSpeed"]; } catch (Exception e) { } try { ram.Price = Request.Form["Price"]; } catch (Exception e) { } try { ram.WarrantyPeriod = Int32.Parse(Request.Form["WarrantyPeriod"]); } catch (Exception e) { } ram.Image = filename; ram.IsDeleted = false; #endregion int num = 0; string price = ram.Price.Replace(".", "").Replace("đ", ""); if (int.TryParse(price, out num) == false) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Giá phải nhập số</p>"; return(RedirectToAction("Add")); } else { if (num < 0) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Nhập giá lớn hơn 0</p>"; return(RedirectToAction("Add")); } } if (_RAMService.InsertRAM(ram)) { return(RedirectToAction("Index")); } else { return(View()); } } else { return(View()); } } catch (Exception e) { } return(View()); }
public ActionResult Add_Post() { // upload image of computer string filename = Request.Form["Image"]; string src = Request.Form["src"]; if (UploadFileService.UploadFileToServerBase64(filename, Constants.VGA_PATH, src)) { var vga = _VGAService.CreateVGA(); #region Get properties try { vga.Name = Request.Form["name"]; } catch (Exception e) { } try { vga.TradeMark = Request.Form["TradeMark"]; } catch (Exception e) { } try { vga.Label = Request.Form["Label"]; } catch (Exception e) { } try { vga.ChipsetManufacturer = Request.Form["ChipsetManufacturer"]; } catch (Exception e) { } try { vga.Model = Request.Form["Model"]; } catch (Exception e) { } try { vga.VGA1 = Request.Form["VGA"]; } catch (Exception e) { } try { vga.BoostClock = Request.Form["BoostClock"]; } catch (Exception e) { } try { vga.VGAMemory = Request.Form["VGAMemory"]; } catch (Exception e) { } try { vga.RamType = Request.Form["RamType"]; } catch (Exception e) { } try { vga.MaxResolution = Request.Form["MaxResolution"]; } catch (Exception e) { } try { vga.Directx = Request.Form["Directx"]; } catch (Exception e) { } try { vga.Size = Request.Form["Size"]; } catch (Exception e) { } try { vga.WarrantyPeriod = Int32.Parse(Request.Form["WarrantyPeriod"]); } catch (Exception e) { } try { vga.Description = Request.Form["Description"]; } catch (Exception e) { } vga.Image = filename; vga.IsDeleted = false; #endregion int num = 0; string price = vga.Price.Replace(".", "").Replace("đ", ""); if (int.TryParse(price, out num) == false) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Giá phải nhập số</p>"; return(RedirectToAction("Add")); } else { if (num < 0) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Nhập giá lớn hơn 0</p>"; return(RedirectToAction("Add")); } } if (_VGAService.InsertVGA(vga)) { return(RedirectToAction("Index")); } } else { return(View()); } return(View()); }
public ActionResult Add_Post() { // upload image of computer string filename = Request.Form["Image"]; string src = Request.Form["src"]; if (UploadFileService.UploadFileToServerBase64(filename, Constants.CASE_PATH, src)) { var Case = _CaseService.CreateCase(); #region get properties try { Case.Name = Request.Form["Name"]; } catch (Exception e) { } try { Case.WarrantyPeriod = Int32.Parse(Request.Form["WarrantyPeriod"]); } catch (Exception e) { } try { Case.TradeMark = Request.Form["TradeMark"]; } catch (Exception e) { } try { Case.Model = Request.Form["Model"]; } catch (Exception e) { } try { Case.Color = Request.Form["Color"]; } catch (Exception e) { } try { Case.Size = Request.Form["Size"]; } catch (Exception e) { } try { Case.MainSupport = Request.Form["MainSupport"]; } catch (Exception e) { } try { Case.USB = Request.Form["USB"]; } catch (Exception e) { } try { Case.DriverBays = Request.Form["DriverBays"]; } catch (Exception e) { } try { Case.Slots = Request.Form["Slots"]; } catch (Exception e) { } try { Case.Price = Request.Form["Price"]; } catch (Exception e) { } try { Case.Description = Request.Form["Description"]; } catch (Exception e) { } Case.IsDelete = false; Case.Image = filename; #endregion string price = Case.Price.Replace(".", "").Replace("đ", ""); if (int.TryParse(price, out int num) == false) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Giá phải nhập số</p>"; return(RedirectToAction("Add")); } else { if (num < 0) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Nhập giá lớn hơn 0</p>"; return(RedirectToAction("Add")); } } if (_CaseService.InsertCase(Case)) { return(RedirectToAction("Index")); } else { return(View()); } } else { return(View()); } }
public void ListAsyncTest1() { var mock = new Mock <IUploadFileRepository>(); mock.Setup(m => m.FindAllAsync(It.IsAny <Expression <Func <UploadFile, UploadFileViewModel> > >())) .Returns(Enumerable.Empty <UploadFileViewModel>().ToAsyncEnumerable()); var service = new UploadFileService(mock.Object); var files = service.ListAsync(); Assert.Empty(files.ToEnumerable()); }
public ActionResult Add_Post() { // upload image of computer string filename = Request.Form["Image"]; string src = Request.Form["src"]; if (UploadFileService.UploadFileToServerBase64(filename, Constants.KEYBOARD_PATH, src)) { var keyboard = _KeyboardService.CreateKeyboard(); #region update properties try { keyboard.Name = Request.Form["Name"]; } catch (Exception e) { } try { keyboard.Description = Request.Form["Description"]; } catch (Exception e) { } try { keyboard.TradeMark = Request.Form["TradeMark"]; } catch (Exception e) { } try { keyboard.WarrantyPeriod = Int32.Parse(Request.Form["WarrantyPeriod"]); } catch (Exception e) { } try { keyboard.Price = Request.Form["Price"]; } catch (Exception e) { } keyboard.IsDeleted = false; keyboard.Image = filename; #endregion int num = 0; string price = keyboard.Price.Replace(".", "").Replace("đ", ""); if (int.TryParse(price, out num) == false) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Giá phải nhập số</p>"; return(RedirectToAction("Add")); } else { if (num < 0) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Nhập giá lớn hơn 0</p>"; return(RedirectToAction("Add")); } } if (_KeyboardService.InsertKeyboard(keyboard)) { Session["submit_message"] = null; return(RedirectToAction("Index")); } else { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #dd0808!important;font-weight: bold;'>Add keyboard failed</p>"; return(View()); } } else { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #dd0808!important;font-weight: bold;'>Add keyboard failed</p>"; return(View()); } }
public async Task <IHttpActionResult> UploadDocument(int targetFolder) { var uploadFileService = new UploadFileService(); UploadProcessingResult uploadResult = await uploadFileService.HandleRequest(Request); if (uploadResult.IsComplete) { // do other stuff here after file upload complete return(Ok()); } return(Ok(HttpStatusCode.Continue)); }
private readonly UploadFileService _uploadFileService; // Добавляем сервис для получения файлов из формы public AccountController( UserManager <User> userManager, RoleManager <IdentityRole> roleManager, SignInManager <User> signInManager, IHostEnvironment environment, UploadFileService uploadFileService) { _userManager = userManager; _roleManager = roleManager; _signInManager = signInManager; _environment = environment; _uploadFileService = uploadFileService; }
/// <summary> /// 删除节点 /// </summary> /// <param name="argument"></param> public string DeleteTreeNode(string argument) { AjaxResult ajaxResult = new AjaxResult(); DoResult doResult = DoResult.Failed; string actionMessage = string.Empty; try { Catalog catalog = catalogService.GetDomain(argument); List<Catalog> childDict = catalogService.All().Where(o => o.ParentID == catalog.ID).ToList(); //删除的目录下的子目录 List<UploadFile> uploadFile = new UploadFileService().All().Where(o => o.CatalogID == catalog.ID).ToList();//删除的目录下的文件 if (childDict.Count > 0 || uploadFile.Count > 0) { actionMessage = "该目录下存在子目录或文件,不允许删除!"; ajaxResult.PromptMsg = actionMessage; } else { if (catalog != null) { catalogService.Delete(catalog); doResult = DoResult.Success; } else { doResult = DoResult.Failed; } string directoryPath = Path.Combine(Server.MapPath("~"), catalog.Path); if (Directory.Exists(directoryPath)) Directory.Delete(directoryPath); //删除物理目录路径 //获取提示信息 actionMessage = string.Format("删除目录{0}成功", catalog.Path); } //记录操作日志 AddActionLog(catalog, doResult, actionMessage); ajaxResult.Result = doResult; ajaxResult.RetValue = catalog.ParentID; ajaxResult.PromptMsg = actionMessage; } catch (Exception ex) { actionMessage = RemarkAttribute.GetEnumRemark(doResult); log.Error(actionMessage, ex); } return JsonConvert.SerializeObject(ajaxResult); }
public ActionResult Add_Post() { try { // upload image of computer string filename = Request.Form["Image"]; string src = Request.Form["src"]; if (UploadFileService.UploadFileToServerBase64(filename, Constants.RADIATOR_PATH, src)) { var radiator = _RadiatorService.CreateRadiator(); #region Get properties try { radiator.Name = Request.Form["Name"]; } catch (Exception e) { } try { radiator.Description = Request.Form["Description"]; } catch (Exception e) { } try { radiator.TradeMark = Request.Form["TradeMark"]; } catch (Exception e) { } try { radiator.Label = Request.Form["Label"]; } catch (Exception e) { } try { radiator.Material = Request.Form["Material"]; } catch (Exception e) { } try { radiator.Speed = Request.Form["Speed"]; } catch (Exception e) { } try { radiator.Size = Request.Form["Size"]; } catch (Exception e) { } try { radiator.FanSize = Request.Form["FanSize"]; } catch (Exception e) { } try { radiator.Socket = Request.Form["Socket"]; } catch (Exception e) { } try { radiator.Price = Request.Form["Price"]; } catch (Exception e) { } radiator.Image = filename; radiator.IsDeleted = false; #endregion int num = 0; string price = radiator.Price.Replace(".", "").Replace("đ", ""); if (int.TryParse(price, out num) == false) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Giá phải nhập số</p>"; return(RedirectToAction("Add")); } else { if (num < 0) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Nhập giá lớn hơn 0</p>"; return(RedirectToAction("Add")); } } if (_RadiatorService.InsertRadiator(radiator)) { return(RedirectToAction("Index")); } } } catch (Exception e) { } return(View()); }
public async Task ListAsyncTest3() { var mock = new Mock <IUploadFileRepository>(); mock.Setup(m => m.FindAllAsync(It.IsAny <Expression <Func <UploadFile, UploadFileViewModel> > >())) .Returns(Enumerable.Range(0, 10).Select(i => new UploadFileViewModel() { Id = i }).ToAsyncEnumerable()); var service = new UploadFileService(mock.Object); var files = service.ListAsync(); Assert.Equal(10, await files.CountAsync()); }
public ActionResult Add_Post() { // upload image of computer string filename = Request.Form["Image"]; string src = Request.Form["src"]; if (UploadFileService.UploadFileToServerBase64(filename, Constants.HARDWARE_PATH, src)) { var hardware = _HardwareService.CreateHardware(); #region get properties try { hardware.Name = Request.Form["Name"]; } catch (Exception e) { } try { hardware.Description = Request.Form["Description"]; } catch (Exception e) { } try { hardware.WarrantyPeriod = Int32.Parse(Request.Form["WarrantyPeriod"]); } catch (Exception e) { } try { hardware.TradeMark = Request.Form["TradeMark"]; } catch (Exception e) { } try { hardware.Memory = Request.Form["Memory"]; } catch (Exception e) { } try { hardware.Label = Request.Form["Label"]; } catch (Exception e) { } try { hardware.ReadSpeed = Request.Form["ReadSpeed"]; } catch (Exception e) { } try { hardware.WriteSpeed = Request.Form["WriteSpeed"]; } catch (Exception e) { } try { hardware.Size = Request.Form["Size"]; } catch (Exception e) { } try { hardware.Price = Request.Form["Price"]; } catch (Exception e) { } hardware.Image = filename; hardware.IsDeleted = false; #endregion int num = 0; string price = hardware.Price.Replace(".", "").Replace("đ", ""); if (int.TryParse(price, out num) == false) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Giá phải nhập số</p>"; return(RedirectToAction("Add")); } else { if (num < 0) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Nhập giá lớn hơn 0</p>"; return(RedirectToAction("Add")); } } if (_HardwareService.InsertHardware(hardware)) { return(RedirectToAction("Index")); } } return(View()); }
public ActionResult DelFile() { bool result = false; try { int detailId = int.Parse(Request.Form["detailId"]); if (detailId > 0) { result = UploadFileService.DelFileByDetailId(detailId); } } catch (Exception ex) { result = false; } return(Json(new { result = result })); }
public IActionResult LibraryDeleteFiles(uint[] fileIds) { try { if (fileIds.Length > 0) { UploadFileService.Update(x => new yoshop_upload_file() { is_delete = 1 }, l => fileIds.Contains(l.file_id)); } } catch (Exception e) { LogManager.Error(GetType(), e); return(No(e.Message)); } return(Yes("删除成功!")); }
public IActionResult LibraryDeleteGroup(int group_id) { try { var _ = UploadGroupService.Delete(l => l.group_id == group_id); if (_) { UploadFileService.Update(x => new yoshop_upload_file { group_id = 0 }, l => l.group_id == group_id); } } catch (Exception e) { LogManager.Error(GetType(), e); return(No(e.Message)); } return(Yes("删除成功!")); }
public async Task <IActionResult> UploadImage(IFormFile file, FileUploadRequest request) { //var file = Request.Form.Files[0]; yoshop_upload_file upload; try { var result = _ = await FileUpload(file); if (result.Code == 0) { return(No(result.Msg)); } upload = new yoshop_upload_file { create_time = DateTimeExtensions.GetCurrentTimeStamp(), file_type = "image", storage = "local", is_delete = 0, group_id = request.group_id, file_size = request.size, file_url = result.Msg, file_name = request.name, extension = Path.GetExtension(request.name).TrimStart('.'), wxapp_id = GetAdminSession().wxapp_id }; UploadFileService.AddEntity(upload); } catch (Exception e) { LogManager.Error(GetType(), e); return(No(e.Message)); } return(YesResult("图片上传成功!", upload)); }
public FilesController(UploadFileService fileService) { _fileService = fileService; }
public CajaController(ServiceApiProject service, MailService mail, UploadFileService upload) { this.ServiceApi = service; this.mail = mail; this.upload = upload; }
/// <summary> /// 保存附件 /// </summary> /// <param name="source"></param> /// <param name="attachUrl"></param> private void SaveData(string source, string attachUrl) { UploadFileService.SaveAttachUrl(source, attachUrl, MenuId, ToKeyId); }
private IEnumerable <yoshop_upload_file> GetUploadFileList(int group_id, string type = "image", FilePageRequest request = null) { return(group_id == -1 ? UploadFileService.LoadPageEntities <uint>(request.current_page, request.per_page, ref request.total, l => l.file_type == type && l.is_delete == 0, l => l.file_id, true) : UploadFileService.LoadPageEntities <uint>(request.current_page, request.per_page, ref request.total, l => l.file_type == type && l.is_delete == 0 && l.group_id == group_id, l => l.file_id, true)); }
public async Task <JsonResult> EditInvoice(InvoiceViewModel model) { if (!ModelState.IsValid) { return(Json(new { Error = "Complete all required fields" })); } if (model.Id.HasValue) { var isAdmin = User.IsInRole("admin"); var invoice = _invoiceService.AllIncluding(item => item.Assignment, item => item.Assignment.Customer, item => item.Assignment.Invoices, item => item.InvoiceAttachments, item => item.InvoiceAttachments.Select(e => e.Attachment)).SingleOrDefault(item => item.Id == model.Id.Value && (isAdmin || item.Assignment.CustomerId == CustomerId)); if (invoice != null) { var assignment = invoice.Assignment; if (!isAdmin && assignment.StatusId != 1) { return(Json(new { Error = "Cannot edit submitted or approved invoices" })); } _uow.BeginTransaction(); invoice.Amount = model.Amount; invoice.PaidAmount = invoice.Amount - (invoice.Amount * assignment.Customer.Rate / 100); invoice.CustomerName = model.CustomerName; invoice.Number = model.Number; invoice.WONumber = model.WONumber; invoice.HoldReason = model.HoldReason; Attachment attachment = null; //if check amount < paid amount and overpayment is null then create overpayment decimal?adjustment = null; if (isAdmin) { invoice.CheckAmount = model.CheckAmount; invoice.CheckNumber = model.CheckNumber; if (model.CheckDate != null) { invoice.CheckDate = model.CheckDate; } //upload check if (Request.Files.Count > 0 && Request.Files["check"] != null) { var ext = Request.Files["check"].FileName.Substring(Request.Files["check"].FileName.LastIndexOf(".", StringComparison.Ordinal)).ToLower(); var tempFileName = UploadFileService.UploadFile(Request.Files["check"]); var invoiceCheck = invoice.InvoiceAttachments.Where(item => item.IsCheck).FirstOrDefault(); if (invoiceCheck?.Attachment != null) { invoiceCheck.Attachment.Path = "/PdfFiles/" + tempFileName + ".pdf"; invoiceCheck.Attachment.OrgFilePath = "/OrgFiles/" + tempFileName + ext; invoiceCheck.Attachment.Name = Request.Form["Check_Name"]; _attachmentService.Update(invoiceCheck.Attachment); } else { invoiceCheck = new InvoiceAttachment { IsCheck = true, Attachment = new Attachment { Path = "/PdfFiles/" + tempFileName + ".pdf", OrgFilePath = "/OrgFiles/" + tempFileName + ext, Name = Request.Form["Check_Name"] } }; if (invoice.InvoiceAttachments == null) { invoice.InvoiceAttachments = new List <InvoiceAttachment>(); } invoice.InvoiceAttachments.Add(invoiceCheck); } attachment = invoiceCheck.Attachment; } if (model.CheckAmount >= 0 && !string.IsNullOrEmpty(model.CheckNumber) && model.CheckDate.HasValue) { if (model.CheckAmount == 0) { invoice.StatusId = 5; } else { invoice.StatusId = 2; } var oldAdjustment = _adjustmentService.FindBy(item => item.OriginInvoiceId == invoice.Id).FirstOrDefault(); if (oldAdjustment != null) { oldAdjustment.Amount = invoice.CheckAmount - invoice.Amount; if (oldAdjustment.Amount == 0) { _adjustmentService.Delete(oldAdjustment); } else { _adjustmentService.Update(oldAdjustment); } } else { if (invoice.CheckAmount != invoice.Amount) { var newAdjustment = new Adjustment { OriginInvoice = invoice, CustomerId = assignment.CustomerId, StatusId = 1, Amount = invoice.CheckAmount - invoice.Amount }; _adjustmentService.Insert(newAdjustment); } } } //implement hold invoices if (model.StatusId.HasValue && (model.StatusId == 3 || model.StatusId == 4)) { //create new assignment var newAssignment = Mapper.Map <Assignment>(assignment); SetAssignmnetLetter(newAssignment); newAssignment.Invoices = new List <Invoice>(); _assignmentService.Insert(newAssignment); _uow.SaveChanges(); invoice.AssignmentId = newAssignment.Id; newAssignment.Invoices.Add(invoice); assignment.Invoices.Remove(invoice); _invoiceService.Update(invoice); _uow.SaveChanges(); _assignmentService.Recaculate(newAssignment); _uow.SaveChanges(); //send email to user var user = UserManager.Users.SingleOrDefault(item => item.Id == invoice.Assignment.UserId); var msg = GetInvoiceHoldEmail(invoice, user); MailService.SendMail(user.Email, "Invoice on Hold", msg); } } _invoiceService.Update(invoice); _assignmentService.Recaculate(assignment); if (assignment.Invoices.Count == 0) { assignment.StatusId = 5; } _uow.SaveChanges(); _uow.Commit(); if (isAdmin) { adjustment = _adjustmentService.All.FirstOrDefault(item => item.OriginInvoiceId == invoice.Id)?.Amount; assignment = _assignmentService.Find(assignment.Id); return(Json(new { Done = 1, Adjustment = adjustment, Path = attachment?.Path, CheckId = attachment?.Id, Total = assignment.Total, TotalPayable = assignment.TotalPayable, Funded = assignment.Funded })); } return(Json(new { Done = 1, Adjustment = adjustment, CheckId = attachment?.Id })); } } return(Json(new { Error = "Invoice not exist." })); }
public ActionResult Add_Post() { // upload image of computer string filename = Request.Form["Image"]; string src = Request.Form["src"]; try { if (UploadFileService.UploadFileToServerBase64(filename, Constants.COMPUTER_PATH, src)) { var computer = _ComputerService.CreateComputer(); #region add properties try { computer.Name = Request.Form["Name"]; } catch (Exception e) { } try { computer.CPU = Request.Form["CPU"]; } catch (Exception e) { } try { computer.RAM = Request.Form["RAM"]; } catch (Exception e) { } try { computer.VideoCard = Request.Form["VideoCard"]; } catch (Exception e) { } try { computer.Hardware = Request.Form["Hardware"]; } catch (Exception e) { } try { computer.SlotSupport = Request.Form["SlotSupport"]; } catch (Exception e) { } try { computer.Display = Request.Form["Display"]; } catch (Exception e) { } try { computer.OS = Request.Form["OS"]; } catch (Exception e) { } try { computer.Type = Request.Form["Type"]; } catch (Exception e) { } try { computer.Trademark = Request.Form["Trademark"]; } catch (Exception e) { } try { computer.Feature = Request.Form["Feature"]; } catch (Exception e) { } try { computer.Color = Request.Form["Color"]; } catch (Exception e) { } try { computer.CPUSeries = Request.Form["CPUSeries"]; } catch (Exception e) { } try { computer.Resolution = Request.Form["Resolution"]; } catch (Exception e) { } try { computer.StandardOfScreen = Request.Form["StandardOfScreen"]; } catch (Exception e) { } try { computer.Size = Request.Form["Size"]; } catch (Exception e) { } try { computer.Mass = Request.Form["Mass"]; } catch (Exception e) { } try { computer.WarrantyPeriod = Int32.Parse(Request.Form["WarrantyPeriod"]); } catch (Exception e) { } try { computer.Price = Request.Form["Price"]; } catch (Exception e) { } try { computer.Description = Request.Form["Description"]; } catch (Exception e) { } try { computer.IsDeleted = false; } catch (Exception e) { } computer.Image = filename; #endregion int num = 0; string price = computer.Price.Replace(".", "").Replace("đ", ""); if (int.TryParse(price, out num) == false) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #f44242!important;font-weight: bold;'>Price phải nhập số</p>"; return(RedirectToAction("Update", new { Id = computer.Id })); } else { if (num < 0) { Session["submit_message"] = "<p class='font-green-sharp' style='font-size: 20px;color: #000000!important;font-weight: bold;'>Nhập giá lớn hơn 0</p>"; return(RedirectToAction("Add")); } } if (_ComputerService.InsertComputer(computer)) { return(RedirectToAction("Index")); } } // create computer } catch (Exception e) { } return(View()); }