public async Task <IActionResult> Put([FromRoute] int id, [FromBody] MemoViewModel viewModel) { try { VerifyUser(); _validateService.Validate(viewModel); if (id != viewModel.Id) { var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(); return(BadRequest(result)); } var model = _mapper.Map <MemoModel>(viewModel); await _service.UpdateAsync(id, model); return(NoContent()); } catch (ServiceValidationException e) { var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e); return(BadRequest(result)); } catch (Exception e) { var result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message).Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result)); } }
public ActionResult CreateMemoPRO(MemoViewModel memoViewModel) { var username = User.Identity.Name; List <Services.NewMemoServices> memo = (List <Services.NewMemoServices>)Session["newMemo"]; int productID = memo[0].SelectedProduct; var selectedPROList = db.Pros.Where(x => x.ProductID == productID).ToList(); var viewModel = new MemoViewModel { PROCollections = selectedPROList }; try { List <MemoPRO> listOfMemoPRO = new List <MemoPRO>(); foreach (var pro in memoViewModel.selectedProID) { var currentPRO = db.Pros.Find(pro); var newMemoPRO = new MemoPRO { PROID = pro, Number = currentPRO.Number }; listOfMemoPRO.Add(newMemoPRO); } memo[0].ListOfMemoPROs = listOfMemoPRO; Session["newMemo"] = memo; return(View(viewModel)); } catch (Exception ex) { ViewBag.Exception = ex; } return(View(viewModel)); }
/// <summary> /// Berfungsi untuk menambahkan pro di halaman edit memo /// </summary> /// <param name="memoViewModel">Sebuah object dari memo view model</param> /// <param name="collection">Object dari FormCollection yang isinya data dari input form halaman view</param> /// <returns>PRO berhasil ditambahkan</returns> public ActionResult AddPRO(MemoViewModel memoViewModel, FormCollection collection) { try { var username = User.Identity.Name; var memoID = collection.GetValues("Memo.ID"); foreach (var pro in memoViewModel.selectedProID) { var proData = db.Pros.Find(pro); var newMemoPRO = new MemoPRO { MemoID = Convert.ToInt32(memoID[0]), PROID = pro, Quantity = proData.Quantity, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.MemoPROes.Add(newMemoPRO); } db.SaveChanges(); Session["message"] = "pro added"; return(RedirectToAction("Edit", "Memo", new { id = memoID[0] })); } catch (Exception ex) { ViewBag.Exception = ex; } return(View("Error")); }
public ActionResult Sell(int?id) { if (id == null) { return(RedirectToAction("Index", "Home")); } // Move a Style in or out of Memo Style style = db.Styles.Find(id); if (style == null) { return(HttpNotFound()); } MemoViewModel m = new MemoViewModel(); m.style = new StyleModel() { Id = style.Id, Image = style.Image, Name = style.StyleName, //Num = style.StyleNum, Qty = style.Quantity, Memod = style.Memos.Sum(s => s.Quantity) }; return(View(m)); }
public async Task <ActionResult> Post([FromBody] MemoViewModel viewModel) { try { VerifyUser(); _validateService.Validate(viewModel); var model = _mapper.Map <MemoModel>(viewModel); await _service.CreateAsync(model); var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok(); return(Created(String.Concat(Request.Path, "/", 0), result)); } catch (ServiceValidationException e) { var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e); return(BadRequest(result)); } catch (Exception e) { var result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result)); } }
/// <summary> /// Berfungsi untuk menambahkan component di halaman edit memo /// </summary> /// <param name="memoID">Sebuah integer yang merupakan id dari memo</param> /// <param name="memoViewModel">Sebuah object dari memo view model</param> /// <returns>Component berhasil ditambahkan</returns> public ActionResult AddMemoComponent(int memoID, MemoViewModel memoViewModel) { try { var username = User.Identity.Name; foreach (var memoComponent in memoViewModel.selectedPROComponentID) { var newMemoComponent = new MemoComponent { MemoID = memoID, ComponentID = memoComponent, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.MemoComponents.Add(newMemoComponent); } db.SaveChanges(); Session["message"] = "component added"; return(RedirectToAction("Edit", "Memo", new { id = memoID })); } catch (Exception ex) { ViewBag.Exception = ex; } return(View("Error")); }
public ActionResult Create() { List <Services.NewMemoServices> memo = (List <Services.NewMemoServices>)Session["newMemo"]; List <Products> productDataList = db.Products.Where(x => x.ProductComposition.Count > 0 && x.PRO.Count > 0).ToList(); if (Session["newMemo"] != null) { ViewBag.ProductID = new SelectList(productDataList, "ID", "PartNumberName", memo[0].Memo.ProductID); ViewBag.MemoTypeID = new SelectList(db.MemoTypes, "ID", "Description", memo[0].Memo.MemoTypeID); ViewBag.Description = memo[0].Memo.Description; var viewModel = new MemoViewModel { Memo = memo[0].Memo }; return(View(viewModel)); } else { ViewBag.ProductID = new SelectList(productDataList, "ID", "PartNumberName"); ViewBag.MemoTypeID = new SelectList(db.MemoTypes, "ID", "Description"); ViewBag.SessionStatus = "null"; return(View()); } }
public async Task <IActionResult> Memorama() { MemoViewModel mvm = new MemoViewModel(); mvm.ListaPokemones = await GetListPokemon(); Random r = new Random(); int[] idsPoke = new int[12] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6 }; for (int i = 0; i <= 11; i++) { var p = r.Next(0, 12); var q = idsPoke[i]; idsPoke[i] = idsPoke[p]; idsPoke[p] = q; } for (int i = 0; i <= idsPoke.Length; i++) { mvm.poke.Foto = $"~/images/{idsPoke[i]}.jpg"; mvm.poke.idPoke = idsPoke[i]; mvm.poke.isSelected = false; mvm.poke.reversoCarta = "~/images/reversoCarta.jpg"; mvm.ListaPokemones.Add(mvm.poke); } return(View("Index")); }
public async Task <IActionResult> Create(MemoViewModel memoViewModel) { try { if (ModelState.IsValid) { var memoModel = _mapper.Map <MemoViewModel, Memo>(memoViewModel); var user = await _userManager.FindByNameAsync(User.Identity.Name); memoModel.UserId = user.Id; var memoId = _memoService.AddMemo(memoModel).Value; if (memoId > 0) { return(Json(new { isValid = true, message = _localizer.GetString(Message.AddedSuccessfully) })); } return(StatusCode(StatusCodes.Status500InternalServerError, _localizer.GetString(Message.SomethingWrongError))); } return(View(memoViewModel)); } catch (Exception ex) { Log.Error(ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, _localizer.GetString(Message.SomethingWrongError))); } }
public JsonResult ReguestMemo(MemoViewModel memoModel, string usercode) { try { memoModel.ImprestMemo.Ref = GenerateRefNo(); memoModel.ImprestMemo.Status = "Pending"; var erpUser = _unitOfWork.Users.GetUsersByCode(usercode); memoModel.ImprestMemo.Personnel = erpUser?.UserCode ?? ""; memoModel.ImprestMemoDetail.ForEach(d => { d.Ref = memoModel.ImprestMemo.Ref; _unitOfWork.ImprestMemoDetail.Add(d); }); _unitOfWork.ImprestMemo.Add(memoModel.ImprestMemo); var procOnlineReq = new ProcOnlineReq { ReqRef = memoModel.ImprestMemo.Ref, DocType = "ONLINE MEMO", Rdate = DateTime.UtcNow, Rtime = DateTime.UtcNow, Usercode = usercode, Status = "Pending" }; var docId = _unitOfWork.Wfrouting.GetFirstOrDefault(r => r.Document.ToUpper() == procOnlineReq.DocType.ToUpper())?.Id.ToString(); if (string.IsNullOrEmpty(docId)) { return(Json(new ReturnData <string> { Success = false, Message = "Sorry, " + procOnlineReq.DocType.ToUpper() + " Not supported at the moment. Please contact the admin" })); } var user = _unitOfWork.HrpEmployee.GetFirstOrDefault(e => e.EmpNo.ToUpper().Equals(usercode.ToUpper())); var workFlowStatus = utils.SaveToWorkFlowCenter(procOnlineReq, user, docId); if (!workFlowStatus.Success) { return(Json(workFlowStatus)); } _unitOfWork.Save(); return(Json(new ReturnData <string> { Success = true, Message = "Memo saved successifully" })); } catch (Exception ex) { return(Json(new ReturnData <string> { Success = false, Message = "An error occurred" })); } }
// NewMemo 頁面 public ActionResult New() { if (Session["auth"] != null) { MemoViewModel memo = new MemoViewModel(); return(View(memo)); } return(RedirectToAction("Index", "Home")); }
public IFeedback <NoValue> EditMemo(MemoViewModel memo) { var feedback = new Feedback <NoValue>(); try { var m = _entities.Memo.Where(me => me.Id == memo.Id).First(); if (m != null) { m.Title = memo.Title; m.Note = memo.Note; m.UpdatedAt = DateTime.Now; var tags = _entities.Tag.Where(t => t.MemoId == memo.Id).ToList(); _entities.Tag.RemoveRange(tags); if (!string.IsNullOrWhiteSpace(memo.Tags)) { List <string> newTagNames = memo.Tags.Split(' ').ToList(); var tagList = new List <Tag>(); foreach (var t in newTagNames) { if (!String.IsNullOrWhiteSpace(t)) { tagList.Add(new Tag() { Name = t, MemoId = memo.Id }); } } _entities.Tag.AddRange(tagList); } _entities.Update(m); _entities.SaveChanges(); feedback.Status = StatusEnum.Success; Log.Information("Memo edited - " + memo.Title); } else { feedback.Message = "Memo not found"; feedback.Status = StatusEnum.Error; Log.Error("EditMemo - " + feedback.Message); } } catch (Exception ex) { feedback.Message = ex.GetBaseException().Message; feedback.Status = StatusEnum.Error; Log.Debug(ex.GetBaseException().Message); } return(feedback); }
// PUT: api/memo public void Put(MemoViewModel editMemo) { if (editMemo != null) { var toEditMemo = db.memo.Where(m => m.memo_id == editMemo.memo_id).FirstOrDefault(); toEditMemo.memo_content = editMemo.memo_content; toEditMemo.title = editMemo.title; toEditMemo.update_date = DateTime.Today; db.SaveChanges(); } }
public ActionResult Create(MemoViewModel memoViewModel) { var productDataList = (from x in db.Products where db.ProductCompositions.Select(y => y.ProductID).Contains(x.ID) select x).ToList(); ViewBag.ProductID = new SelectList(productDataList, "ID", "PartNumberName"); ViewBag.MemoTypeID = new SelectList(db.MemoTypes, "ID", "Description"); var username = User.Identity.Name; try { if (Session["newMemo"] == null) { List <Services.NewMemoServices> memo = new List <Services.NewMemoServices>(); List <MemoPRO> listOfMemoPRO = new List <MemoPRO>(); memoViewModel.Memo.ProductID = memoViewModel.ProductID; memoViewModel.Memo.MemoTypeID = memoViewModel.MemoTypeID; memo.Add(new Services.NewMemoServices(memoViewModel.Memo, memoViewModel.ProductID, listOfMemoPRO, "")); Session["newMemo"] = memo; return(RedirectToAction("CreateMemoPRO")); } else { List <Services.NewMemoServices> memo = (List <Services.NewMemoServices>)Session["newMemo"]; if (memo[0].Memo.ProductID != memoViewModel.ProductID) { memo[0].ListOfMemoPROs = null; memo[0].Memo.ProductID = memoViewModel.ProductID; memo[0].SelectedProduct = memoViewModel.ProductID; memo[0].Memo.MemoTypeID = memoViewModel.MemoTypeID; memo[0].Memo.Description = memoViewModel.Memo.Description; return(RedirectToAction("CreateMemoPRO")); } else { memo[0].Memo.ProductID = memoViewModel.ProductID; memo[0].SelectedProduct = memoViewModel.ProductID; memo[0].Memo.MemoTypeID = memoViewModel.MemoTypeID; memo[0].Memo.Description = memoViewModel.Memo.Description; return(RedirectToAction("CreateMemoPRO")); } } } catch (Exception ex) { ViewBag.Exception = ex; } return(View("Error")); }
// POST: api/memo public void Post(MemoViewModel editMemo) { memo newMemo = new memo { create_date = DateTime.Today, enable = 1, title = editMemo.title, memo_content = editMemo.memo_content, update_date = DateTime.Today }; db.memo.Add(newMemo); db.SaveChanges(); }
/// <summary> /// Merupakan fungsi yang digunakan untuk mengubah data memo pro /// </summary> /// <param name="collection">Object dari FormCollection yang isinya data dari input form halaman view</param> /// <param name="memoViewModel">Sebuah object view model dari MemoViewModel</param> /// <returns></returns> public ActionResult UpdateMemoPRO(FormCollection collection, MemoViewModel memoViewModel) { List <Services.NewMemoServices> memo = (List <Services.NewMemoServices>)Session["newMemo"]; string[] quantity = collection.GetValues("quantityPRO"); string[] currentPROID = collection.GetValues("proID"); memo[0].Message = ""; int productID = memo[0].SelectedProduct; var selectedPRO = db.Pros.Where(x => x.ProductID == productID).ToList(); var viewModel = new MemoViewModel { PROCollections = selectedPRO }; for (int i = 0; i < memo[0].ListOfMemoPROs.Count; i++) { var existPRO = db.Pros.Find(Convert.ToInt32(currentPROID[i])); if (quantity[i] == "" || quantity[i] == null) { ViewBag.ErrorMessage = "Quantity value form can't be empty"; memo[0].Message = ViewBag.ErrorMessage; return(new RedirectResult("CreateMemoPRO")); } else { if (Convert.ToInt32(quantity[i]) <= existPRO.Quantity && Convert.ToInt32(quantity[i]) > 0) { int proID = Convert.ToInt32(currentPROID[i]); var currentMemoPRO = memo[0].ListOfMemoPROs.Where(x => x.PROID == proID).FirstOrDefault(); currentMemoPRO.Quantity = Convert.ToInt32(quantity[i]); } else if (Convert.ToInt32(quantity[i]) == 0) { ViewBag.ErrorMessage = "Quantity value can't be 0 or form can't be empty"; memo[0].Message = ViewBag.ErrorMessage; return(new RedirectResult("CreateMemoPRO")); } else { ViewBag.Message = "Quantity can't be more than PRO quantity"; memo[0].Message = ViewBag.Message; return(new RedirectResult("CreateMemoPRO")); } } } return(RedirectToAction("CreateMemoComponent")); }
public ActionResult editMemo(MemoViewModel editmemo) { string editToString = JsonConvert.SerializeObject(editmemo); using (var httpClient = new HttpClient()) { // http post var putTask = httpClient.PutAsync(_baseAddress, new StringContent(editToString, Encoding.UTF8, "application/json")); putTask.Wait(); if (putTask.Result.IsSuccessStatusCode) { TempData["edit"] = true; } } return(RedirectToAction("Index")); }
// 修改 做法1 (get該筆資訊) //public ActionResult editMemo(int id) //{ // // 是否登入 // if (Session["auth"] != null) // { // Uri address = new Uri(_baseAddress, "memo/"+id); // using (var httpClient = new HttpClient()) // { // var responseTask = httpClient.GetAsync(address); // // 等待http回傳 // responseTask.Wait(); // var result = responseTask.Result; // if (result.IsSuccessStatusCode) // { // var readTask = result.Content.ReadAsStringAsync(); // memo memo = JsonConvert.DeserializeObject<memo>(readTask.Result); // readTask.Wait(); // // ViewModel // MemoViewModel editmemo = new MemoViewModel() // { // title = memo.title, // memo_id = id, // memo_content = memo.memo_content, // update_date = memo.update_date.ToString("yyyy/MM/dd") // }; // return View(editmemo); // } // } // } // return RedirectToAction("Index", "Home"); //} #endregion // 修改 做法2 (傳入該筆資訊) public ActionResult editMemo(memo thisMemo) { // 是否登入 if (Session["auth"] != null) { // ViewModel MemoViewModel editmemo = new MemoViewModel() { title = thisMemo.title, memo_id = thisMemo.memo_id, memo_content = thisMemo.memo_content, update_date = thisMemo.update_date.ToString("yyyy/MM/dd") }; return(View(editmemo)); } return(RedirectToAction("Index", "Home")); }
public ActionResult Edit(int id, MemoViewModel memoViewModel) { var memoData = db.Memos.Find(id); var memoPROList = db.MemoPROes.Where(x => x.MemoID == id).ToList(); var memoComponentList = db.MemoComponents.Where(x => x.MemoID == id).ToList(); var selectedPROList = (from x in db.Pros where x.ProductID == memoData.ProductID && !db.MemoPROes.Select(y => y.PROID).Contains(x.ID) select x).ToList(); var selectedProComponentList = (from x in db.ProductCompositions where x.ProductID == memoData.ProductID && !db.MemoComponents.Where(y => y.MemoID == memoData.ID).Select(y => y.ComponentID).Contains(x.ComponentID) select x).ToList(); ViewBag.MemoTypeID = new SelectList(db.MemoTypes, "ID", "Description", memoData.MemoTypeID); ViewBag.ProductID = new SelectList(db.Products, "ID", "Name", memoData.ProductID); var username = User.Identity.Name; var viewModel = new MemoViewModel { Memo = memoData, ListofMemoPRO = memoPROList, ListofMemoComponents = memoComponentList, PROCollections = selectedPROList, ProductCompositions = selectedProComponentList }; try { memoData.MemoTypeID = memoViewModel.MemoTypeID; memoData.Description = memoViewModel.Memo.Description; db.SaveChanges(); ViewBag.Success = "success"; ViewBag.MemoID = memoData.ID; return(View(viewModel)); } catch (Exception ex) { ViewBag.Exception = ex; } return(View("Error")); }
public ActionResult Details(int?id, int?page) { if (id.HasValue) { Session.Remove("message"); var memoData = db.Memos.Find(id); if (memoData != null) { var memoPROList = db.MemoPROes.Where(x => x.MemoID == id).ToList(); var memoComponentList = db.MemoComponents.Where(x => x.MemoID == id).ToList(); var selectedPROList = (from x in db.Pros where x.ProductID == memoData.ProductID && !db.MemoPROes.Select(y => y.PROID).Contains(x.ID) select x).ToList(); var selectedProComponentList = (from x in db.ProductCompositions where x.ProductID == memoData.ProductID && !db.MemoComponents.Where(y => y.MemoID == memoData.ID).Select(y => y.ComponentID).Contains(x.ComponentID) select x).ToList(); //var selectedProComponentList = db.ProductCompositions.Where(x => x.ProductID == memoData.ProductID).ToList(); var viewModel = new MemoViewModel { Memo = memoData, ListofMemoPRO = memoPROList, ListofMemoComponents = memoComponentList, PROCollections = selectedPROList, ProductCompositions = selectedProComponentList }; ViewBag.Page = page.ToString(); return(View(viewModel)); } else { ViewBag.ErrorMessage = "Sorry we couldn't find this memo"; return(View("Error")); } } else { return(RedirectToAction("Index", "Memo")); } }
public ActionResult addMemo(MemoViewModel memo) { //驗證 if (!ModelState.IsValid) { return(View("New", memo)); } string memoToString = JsonConvert.SerializeObject(memo); using (var httpClient = new HttpClient()) { // http post var postTask = httpClient.PostAsync(_baseAddress, new StringContent(memoToString, Encoding.UTF8, "application/json")); postTask.Wait(); if (postTask.Result.IsSuccessStatusCode) { TempData["edit"] = true; } } return(RedirectToAction("Index", "Memo")); }
public JsonResult ReguestMemo([FromBody] MemoViewModel memoModel, string usercode) { memoModel.ImprestMemo.Sdate = memoModel.ImprestMemo.Sdate.GetValueOrDefault().AddDays(1); memoModel.ImprestMemo.Edate = memoModel.ImprestMemo.Edate.GetValueOrDefault().AddDays(1); var token = _tokenValidator.Validate(HttpContext); if (!token.Success) { return(Json(new ReturnData <string> { Success = false, NotAuthenticated = true, Message = $"Unauthorized:-{token.Message}", })); } var result = _unisolApiProxy.ReguestMemo(memoModel, usercode).Result; var response = JsonConvert.DeserializeObject <ReturnData <dynamic> >(result); return(Json(response)); }
public ActionResult Edit(int?id) { if (id.HasValue) { var memoData = db.Memos.Find(id); if (memoData != null) { var memoPROList = db.MemoPROes.Where(x => x.MemoID == id).ToList(); var memoComponentList = db.MemoComponents.Where(x => x.MemoID == id).ToList(); var selectedPROList = (from x in db.Pros where x.ProductID == memoData.ProductID && !db.MemoPROes.Select(y => y.PROID).Contains(x.ID) select x).ToList(); var selectedProComponentList = (from x in db.ProductCompositions where x.ProductID == memoData.ProductID && !db.MemoComponents.Where(y => y.MemoID == memoData.ID).Select(y => y.ComponentID).Contains(x.ComponentID) select x).ToList(); ViewBag.MemoTypeID = new SelectList(db.MemoTypes, "ID", "Description", memoData.MemoTypeID); ViewBag.ProductID = new SelectList(db.Products, "ID", "Name", memoData.ProductID); var viewModel = new MemoViewModel { Memo = memoData, ListofMemoPRO = memoPROList, ListofMemoComponents = memoComponentList, PROCollections = selectedPROList, ProductCompositions = selectedProComponentList }; return(View(viewModel)); } else { ViewBag.ErrorMessage = "Sorry we couldn't find this memo"; return(View("Error")); } } else { return(RedirectToAction("Index", "Memo")); } }
public IActionResult Edit(MemoViewModel memoViewModel) { try { if (ModelState.IsValid) { var memoModel = _mapper.Map <MemoViewModel, Memo>(memoViewModel); var updatedModel = _memoService.UpdateMemo(memoModel); if (updatedModel.Succeeded) { return(Json(new { isValid = true, message = _localizer.GetString(Message.UpdatedSuccessfully) })); } return(StatusCode(StatusCodes.Status500InternalServerError, _localizer.GetString(Message.SomethingWrongError))); } return(View(memoViewModel)); } catch (Exception ex) { Log.Error(ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, _localizer.GetString(Message.SomethingWrongError))); } }
public ActionResult CreateMemoComponent(MemoViewModel memoViewModel) { List <Services.NewMemoServices> memo = (List <Services.NewMemoServices>)Session["newMemo"]; var currentMemo = memo[0].Memo; var currentProduct = db.Products.Find(currentMemo.ProductID); var currentMemoType = db.MemoTypes.Find(currentMemo.MemoTypeID); var currentListOfMemoPRO = memo[0].ListOfMemoPROs; var listOfProductComposition = db.ProductCompositions.Where(x => x.ProductID == currentMemo.ProductID).ToList(); var viewModel = new MemoViewModel { Product = currentProduct, Memo = currentMemo, MemoType = currentMemoType, ListofMemoPRO = currentListOfMemoPRO, ProductCompositions = listOfProductComposition }; if (memo[0].Message != null) { Session.Remove(memo[0].Message); } return(View(viewModel)); }
public ActionResult Memo(int?id) { if (id == null) { return(RedirectToAction("Index", "Home")); } Style style = db.Styles.Find(id); if (style == null) { return(HttpNotFound()); } // Move a Style in or out of Memo MemoViewModel m = new MemoViewModel(); m.style = new StyleModel() { Id = style.Id, Image = style.Image, Name = style.StyleName, //Num = style.StyleNum, Qty = style.Quantity, Memod = style.Memos.Sum(s => s.Quantity) }; m.Memos = new List <MemoModel>(); m.numPresentersWithStyle = 0; foreach (Memo i in db.Memos.Where(x => x.StyleID == style.Id).Include(x => x.Presenter)) { MemoModel mm = new MemoModel() { Id = i.Id, Quantity = i.Quantity, date = i.Date, PresenterName = i.Presenter.Name, PresenterPhone = i.Presenter.Phone, PresenterEmail = i.Presenter.Email, Notes = i.Notes }; m.Memos.Add(mm); m.numPresentersWithStyle++; } m.Presenters = new List <SelectListItem>(); m.CompanyId = style.Collection.CompanyId; m.NewExistingPresenterRadio = 2; foreach (Presenter i in db.Presenters.Where(w => w.CompanyId == m.CompanyId)) { SelectListItem sli = new SelectListItem() { Text = i.Name, Value = i.Id.ToString(), }; m.Presenters.Add(sli); // select only new presenter if there aren't any presenters m.NewExistingPresenterRadio = 1; } m.SendReturnMemoRadio = 1; m.PresenterName = ""; ViewBag.CollectionId = style.CollectionId; return(View(m)); }
/// <summary> /// Berfungsi untuk menambahkan memo baru ke dalam database /// </summary> /// <param name="memoViewModel">Sebuah object dari memo view model</param> /// <returns>Ketika memo berhasil ditambahkan, maka web akan meredirect ke halaman detail</returns> public ActionResult SaveMemo(MemoViewModel memoViewModel) { List <Services.NewMemoServices> memo = (List <Services.NewMemoServices>)Session["newMemo"]; var currentMemo = memo[0].Memo; var currentListOfMemoPRO = memo[0].ListOfMemoPROs; try { var username = User.Identity.Name; var newMemo = new Memo { Description = currentMemo.Description, MemoTypeID = currentMemo.MemoTypeID, ProductID = currentMemo.ProductID, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.Memos.Add(newMemo); db.SaveChanges(); var newMemoID = newMemo.ID; foreach (var memoPro in currentListOfMemoPRO) { var newMemoPRO = new MemoPRO { MemoID = newMemoID, PROID = memoPro.PROID, Quantity = memoPro.Quantity, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.MemoPROes.Add(newMemoPRO); } db.SaveChanges(); var selectedComponent = memoViewModel.SelectedComponent; foreach (int componentID in memoViewModel.SelectedComponent) { var newMemoComponent = new MemoComponent { MemoID = newMemoID, ComponentID = componentID, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.MemoComponents.Add(newMemoComponent); } db.SaveChanges(); Session.Remove("newMemo"); return(RedirectToAction("Details", "Memo", new { id = newMemoID })); } catch (Exception ex) { ViewBag.Exception = ex; } return(View("Error")); }
MemoViewModel MapToMemoViewModel(Memo m) { MemoViewModel model = new MemoViewModel(); model.Id = m.Id.ToString(); m.Name = m.Name; return model; }
public IActionResult EditMemo(MemoViewModel model) { _memoService.EditMemo(model); return(RedirectToAction("Index")); }
public ActionResult Memo(MemoViewModel m) { ModelState.Clear(); OJewelryDB dc = new OJewelryDB(); // populate style data Style sdb = dc.Styles.Find(m.style.Id); m.style.Name = sdb.StyleName; //m.style.Num = sdb.StyleNum; m.style.Qty = sdb.Quantity; if (m.SendReturnMemoRadio == 1) { if (m.NewExistingPresenterRadio == 2) { //Memo a new presenter if (String.IsNullOrEmpty(m.PresenterName)) { ModelState.AddModelError("Presenter Name", "Name is required for new Presenters."); } if (String.IsNullOrEmpty(m.PresenterEmail) && String.IsNullOrEmpty(m.PresenterPhone)) { ModelState.AddModelError("Presenter Contact Info", "Phone or Email is required for new Presenters."); } Presenter p = new Presenter() { CompanyId = m.CompanyId, Name = m.PresenterName, Email = m.PresenterEmail, Phone = m.PresenterPhone, }; dc.Presenters.Add(p); m.PresenterId = p.Id; } else { // Memo an existing presenter - nothing to validate in this case as they just selected a Presenter from the list } // create new memo, reduce inventory sdb.Quantity -= m.SendQty; String note = "Sending " + m.SendQty.ToString() + " items to " + m.PresenterName + " on " + DateTime.Now.ToString(); Memo mo = new Memo() { Quantity = m.SendQty, Date = DateTime.Now, Notes = note, PresenterID = m.PresenterId, StyleID = m.style.Id, }; dc.Memos.Add(mo); if (m.SendQty > m.style.Qty) { ModelState.AddModelError("Send Quantity", "You cannot memo more items than you have in inventory."); } if (m.SendQty < 1) { ModelState.AddModelError("Send Quantity", "You can only memo a positive number of items."); } } else { //Return Items from Presenter // iterate thru the memos to take items back. Increase the inventory as appropriate. If all items are returned, delete the memo foreach (MemoModel memo in m.Memos) { if (memo.ReturnQty < 0) { ModelState.AddModelError("Return Style", "You can only return a positive number to inventory."); } if (memo.ReturnQty > 0) { if (memo.ReturnQty > memo.Quantity) { ModelState.AddModelError("Return Style", "You can't return more items than were memo'd out."); } // update db Memo mdb = dc.Memos.Find(memo.Id); if (mdb.Quantity == memo.ReturnQty) { // remove the row and remove item from collection dc.Memos.Remove(mdb); } else { // decrease the amount mdb.Quantity -= memo.ReturnQty; } sdb.Quantity += memo.ReturnQty; } // ReturnQty is 0, no action } } if (ModelState.IsValid) { // Save changes, go to clientlist dc.SaveChanges(); //return ClientList(); //return View(m); } return(Memo(m.style.Id)); }
public void Should_Success_Validate_All_Null_Data() { var viewModel = new MemoViewModel(); Assert.True(viewModel.Validate(null).Count() > 0); }
public void AddMemo() { var model = new MemoViewModel(); IoC.Get<IWindowManager>().ShowDialog(model); }