public async Task <IActionResult> UpdateProfileUser(IFormFile file, UserViewModel model) { var userLogin = _userManager.GetUserName(User); //variabel error jika ada var hasilError = ""; //Tambahkan Link Akses Direktori var link1 = "wwwroot/dist/img"; var link2 = "wwwroot\\dist\\img\\"; //model baru jika ada error var modelSimpan = (from user in _dbContext.AspNetUsers join role in _dbContext.Roles on user.RolesId equals Convert.ToString(role.Id) join vendor in _dbContext.AspNetVendor on user.UserName equals vendor.UserId into joinVendor from Vendor in joinVendor.DefaultIfEmpty() where user.UserName == userLogin select new UserViewModel { aspnetUser = user, roles = role, AspNetVendor = Vendor }).FirstOrDefault(); var photos = modelSimpan.aspnetUser.Picture; if (photos == null) { photos = "avatar5.png"; } ViewBag.Picture = photos; //Setelah Model Disimpan lakukan Proses if (userLogin == null) { return(Redirect("/Account/Login")); } var aspnetUser = _dbContext.AspNetUsers.FirstOrDefault(a => a.UserName == userLogin); if (file == null && model.aspnetUser.PhoneNumber != null) { aspnetUser.PhoneNumber = model.aspnetUser.PhoneNumber; _dbContext.AspNetUsers.Update(aspnetUser); await _dbContext.SaveChangesAsync(); } else if (file != null && model.aspnetUser.PhoneNumber != null) { string uploadImage = await _uploadImages.ImagesUpload(file, link1, link2); if (uploadImage == "") { hasilError = "Couldn't Get The File"; ViewBag.ErrorPage = hasilError; return(View("ProfileUser", modelSimpan)); } else if (uploadImage != "File must be either .jpg, .jpeg, .png and Maximum Size is 4MB") { if (aspnetUser.Picture != null) { string dispose = _deleteImages.Delete(aspnetUser.Picture, link2); } aspnetUser.Picture = uploadImage; aspnetUser.PhoneNumber = model.aspnetUser.PhoneNumber; _dbContext.AspNetUsers.Update(aspnetUser); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(ProfileUser))); } else { hasilError = uploadImage; ViewBag.ErrorPage = hasilError; return(View("ProfileUser", modelSimpan)); } } else if (file != null) { //Lempar Image dan Link Ke Class Upload string uploadImage = await _uploadImages.ImagesUpload(file, link1, link2); if (uploadImage == "") { hasilError = "Couldn't Get The File"; ViewBag.ErrorPage = hasilError; return(View("ProfileUser", modelSimpan)); } else if (uploadImage != "File must be either .jpg, .jpeg, .png and Maximum Size is 4MB") { if (aspnetUser.Picture != null) { string dispose = _deleteImages.Delete(aspnetUser.Picture, link2); } aspnetUser.Picture = uploadImage; _dbContext.AspNetUsers.Update(aspnetUser); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(ProfileUser))); } else { hasilError = uploadImage; ViewBag.ErrorPage = hasilError; return(View("ProfileUser", modelSimpan)); } } else { return(RedirectToAction(nameof(ProfileUser))); } return(RedirectToAction(nameof(ProfileUser))); }
public async Task <IActionResult> AddLineItems(IFormFile gambarItem, PurchaseRequestViewModel model) { //make link to the PR images var link1 = "wwwroot/dist/AppsImages/PR"; var link2 = "wwwroot\\dist\\AppsImages\\PR\\"; string resultupload = ""; //Upload The Images string upload = await _uploadImages.ImagesUpload(gambarItem, link1, link2); if (upload == "") { resultupload = ""; } else if (upload != "File must be either .jpg, .jpeg, .png and Maximum Size is 4MB") { resultupload = upload; } else { resultupload = ""; } //get not required input var vatProd = model.PRLineDetail.VatprodPostingGroup; var Desc2 = model.PRLineDetail.Description2; var UoM = model.PRLineDetail.UnitofMeasure; var VatBus = model.PRLineDetail.VatbusPostingGroup; var InvenPost = model.PRLineDetail.InventoryPostingGroup; var ItemCatCode = model.PRLineDetail.ItemCategoryCode; var ProductGroup = model.PRLineDetail.ProductGroupCode; var GenProd = model.PRLineDetail.GenProdPostingGroup; var a = gambarItem; //Change null to "" if (vatProd == null) { vatProd = ""; } if (Desc2 == null) { Desc2 = ""; } if (UoM == null) { UoM = ""; } if (VatBus == null) { VatBus = ""; } if (InvenPost == null) { InvenPost = ""; } if (ItemCatCode == null) { ItemCatCode = ""; } if (ProductGroup == null) { ProductGroup = ""; } if (GenProd == null) { GenProd = ""; } var SeqLineNumber = newSeqLineNoPR(model.PRLineDetail.DocumentNo); //Get Header PR var Header = _bmlContext.PurchaseRequisitionHeader.SingleOrDefault(a => a.RequisitionNo == model.PRLineDetail.DocumentNo); //Add PR Line to DB PurchaseRequisitionLine prLine = new PurchaseRequisitionLine() { RequisitionheaderId = Header.RequisitionHeaderId, DocumentNo = model.PRLineDetail.DocumentNo, SeqLineNo = SeqLineNumber, RecordType = model.PRLineDetail.RecordType, RecordNo = model.PRLineDetail.RecordNo, Description = model.PRLineDetail.Description, Description2 = Desc2, Quantity = model.PRLineDetail.Quantity, UnitofMeasure = UoM, VendorNo = "", DirectUnitCost = model.PRLineDetail.DirectUnitCost, VatbusPostingGroup = VatBus, VatprodPostingGroup = vatProd, InventoryPostingGroup = InvenPost, DueDate = Header.DueDate, RequesterId = _userManager.GetUserName(User), Confirmed = 0, ShortcutDimension1Code = Header.ShortcutDimension1Code, ShortcutDimension2Code = Header.ShortcutDimension2Code, LocationCode = Header.LocationCode, RecurringMethod = 0, ExpirationDate = Header.ExpirationDate, RecurringFrequency = "", OrderDate = Header.OrderDate, VendorItemNo = "", SalesOrderNo = "", SelltoCustomerNo = "", ShiptoCode = "", OrderAddressCode = "", CurrencyCode = "IDR", CurrencyFactor = 1, ProdOrderNo = "", VariantCode = "", BinCode = "", QtyperUnitofMeasure = 1, UnitofMeasureCode = UoM, QuantityBase = model.PRLineDetail.Quantity, DemandType = 0, DemandSubtype = 0, DemandOrderNo = "", DemandLineNo = 0, DemandRefNo = 0, Status = Header.Status, DemandDate = Header.ExpirationDate, DemandQuantity = 0, DemandQuantityBase = 0, NeededQuantity = 0, NeededQuantityBase = 0, Reserve = 0, QtyperUomdemand = 0, UnitOfMeasureCodeDemand = "", SupplyFrom = "", OriginalItemNo = "", OriginalVariantCode = "", Level = 0, DemandQtyAvailable = 0, UserId = "", ItemCategoryCode = ItemCatCode, Nonstock = 0, PurchasingCode = "", ProductGroupCode = ProductGroup, TransferfromCode = "", TransferShipmentDate = Header.ExpirationDate, LineDiscountPercent = 0, OrderPromisingSubLineNo = 0, RoutingNo = "", OperationNo = "", WorkCenterNo = "", ProdOrderLineNo = 0, Mpsorder = 0, PlanningFlexibility = 0, RoutingReferenceNo = 0, GenProdPostingGroup = GenProd, GenBusinessPostingGroup = "", LowLevelCode = 0, ProductionBomno = "", RoutingVersionCode = "", RoutingType = 0, OriginalQuantity = model.PRLineDetail.Quantity, FinishedQuantity = 0, RemainingQuantity = model.PRLineDetail.Quantity, OriginalDueDate = Header.ExpirationDate, ScrapPercent = 0, StartingDate = Header.ExpirationDate, StartingTime = Header.ExpirationDate, EndingDate = Header.ExpirationDate, EndingTime = Header.ExpirationDate, ProductionBomversionCode = "", IndirectCostPercent = 0, OverheadRate = 0, UnitCost = model.PRLineDetail.DirectUnitCost, CostAmount = (model.PRLineDetail.Quantity * model.PRLineDetail.DirectUnitCost), ReplenishmentSystem = 0, RefOrderNo = "", RefOrderType = 0, RefOrderStatus = 0, RefLineNo = 0, NoSeries = "", FinishedQtyBase = 0, QuantityPo = 0, RemainingQtyBase = model.PRLineDetail.Quantity, RelatedtoPlanningLine = 0, PlanningLevel = 0, PlanningLineOrigin = 0, ActionMessage = 0, AcceptActionMessage = 0, NetQuantityBase = 0, StartingDateTime = Header.ExpirationDate, EndingDateTime = Header.ExpirationDate, OrderPromisingId = "", OrderPromisingLineNo = 0, OrderPromisingLineId = 0, Priority = Header.Priority, RequestNotes = Header.RequestNotes, RowStatus = 0, CreatedBy = _userManager.GetUserName(User), CreatedTime = DateTime.Now, Picture = resultupload }; _bmlContext.PurchaseRequisitionLine.Add(prLine); _bmlContext.SaveChanges(); return(Json(new { status = true, message = "Your File Saved Successfull" })); }