public SouvenirStockViewModel GetSouvenirStockById(int id) { using (MarcommEntities db = new MarcommEntities()) { var souvenir = (from p in db.t_souvenir where p.id.Equals(id) && p.is_delete == false select p).SingleOrDefault(); SouvenirStockViewModel Souvenir = new SouvenirStockViewModel(); Souvenir.id = souvenir.id; Souvenir.code = souvenir.code; Souvenir.tEventId = souvenir.t_event_id; Souvenir.requestBy = souvenir.request_by; Souvenir.requestDate = souvenir.request_date; Souvenir.requestDueDate = souvenir.request_due_date; Souvenir.note = souvenir.note; Souvenir.status = souvenir.status; Souvenir.requestByToFullName = GetFullNameFromIdEmployee(souvenir.request_by); Souvenir.createdByToFullName = GetFullNameFromIdEmployee(Convert.ToInt32(souvenir.created_by)); Souvenir.eventIdToEventCode = GetEventCodeFromEventId(souvenir.t_event_id); return(Souvenir); } }
public JsonResult CloseSettlementSouvenirRequest(int id) { long UserId = 0; if (Session["DetailUser"] != null) { var User = Session["DetailUser"] as UserViewModel; UserId = User.ID; } SouvenirStockViewModel Souvenir = new SouvenirStockViewModel(); Souvenir.id = id; Souvenir.updateBy = UserId; string json = JsonConvert.SerializeObject(Souvenir); var buffer = Encoding.UTF8.GetBytes(json); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); string API_END_POINT = API_URL + "SouvenirRequest/CloseSettlementSouvenirRequest/"; HttpClient client = new HttpClient(); HttpResponseMessage response = client.PutAsync(API_END_POINT, byteContent).Result; var result = response.Content.ReadAsStringAsync().Result.ToString(); return(Json(bool.Parse(result), JsonRequestBehavior.AllowGet)); }
public List <SouvenirStockViewModel> GetAllSouvenirStock(SearchTransactionSouvenirViewModel parameters) { using (MarcommEntities db = new MarcommEntities()) { bool NullCode = string.IsNullOrWhiteSpace(parameters.code); bool NullRequestBy = string.IsNullOrWhiteSpace(parameters.requestBy); bool NullRequestDate = string.IsNullOrWhiteSpace(parameters.requestDate); bool NullDueDate = string.IsNullOrWhiteSpace(parameters.dueDate); bool NullStatus = string.IsNullOrWhiteSpace(parameters.status); bool NullCreatedDate = string.IsNullOrWhiteSpace(parameters.createdDate); bool NullCreatedBy = string.IsNullOrWhiteSpace(parameters.createdBy); DateTime?requestDate = NullRequestDate ? (DateTime?)null : DateTime.Parse( DateTime.ParseExact(parameters.requestDate, "dd'-'MM'-'yyyy", CultureInfo.InvariantCulture).ToString("MM'/'dd'/'yyyy")); DateTime?dueDate = NullDueDate ? (DateTime?)null : DateTime.Parse( DateTime.ParseExact(parameters.dueDate, "dd'-'MM'-'yyyy", CultureInfo.InvariantCulture).ToString("MM'/'dd'/'yyyy")); DateTime?createdDate = NullCreatedDate ? (DateTime?)null : DateTime.Parse( DateTime.ParseExact(parameters.createdDate, "dd'-'MM'-'yyyy", CultureInfo.InvariantCulture).ToString("MM'/'dd'/'yyyy")); var souvenir_stock = (from p in db.t_souvenir where p.is_delete == false select p).ToList(); souvenir_stock = !NullCode ? (from p in souvenir_stock where p.code.Contains(parameters.code) select p).ToList() : souvenir_stock; souvenir_stock = !NullRequestDate ? (from p in souvenir_stock where DateTime.Compare((DateTime)p.request_date, (DateTime)requestDate) == 0 select p).ToList() : souvenir_stock; souvenir_stock = !NullDueDate ? (from p in souvenir_stock where DateTime.Compare((DateTime)p.request_due_date, (DateTime)dueDate) == 0 select p).ToList() : souvenir_stock; souvenir_stock = !NullCreatedDate ? (from p in souvenir_stock where DateTime.Compare((DateTime)p.created_date, (DateTime)createdDate) == 0 select p).ToList() : souvenir_stock; souvenir_stock = !NullRequestBy ? (from p in souvenir_stock where p.request_by.Equals( (from q in db.m_employee where !q.id_delete && (q.first_name + " " + q.last_name).Contains(parameters.requestBy) select q.id).SingleOrDefault()) select p).ToList() : souvenir_stock; souvenir_stock = !NullCreatedBy ? (from p in souvenir_stock where p.created_by.Equals(Convert.ToInt64( (from q in db.m_employee where !q.id_delete && (q.first_name + " " + q.last_name).Contains(parameters.createdBy) select q.id).SingleOrDefault())) select p).ToList() : souvenir_stock; souvenir_stock = !NullStatus ? (from p in souvenir_stock where GetStatusId(parameters.status.ToLower()).Contains((int)p.status) select p).ToList() : souvenir_stock; List <SouvenirStockViewModel> SouvenirStock = new List <SouvenirStockViewModel>(); foreach (var souvenir in souvenir_stock) { SouvenirStockViewModel Souvenir = new SouvenirStockViewModel(); Souvenir.id = souvenir.id; Souvenir.code = souvenir.code; Souvenir.requestBy = souvenir.request_by; Souvenir.requestDate = souvenir.request_date; Souvenir.requestDueDate = souvenir.request_due_date; Souvenir.status = souvenir.status; Souvenir.createdDate = souvenir.created_date; Souvenir.createdBy = souvenir.created_by; Souvenir.requestByToFullName = GetFullNameFromIdEmployee(souvenir.request_by); Souvenir.createdByToFullName = GetFullNameFromIdEmployee(Convert.ToInt32(souvenir.created_by)); SouvenirStock.Add(Souvenir); } return(SouvenirStock); } }
public bool Put(SouvenirStockViewModel Souvenir) { try { service.ApprovalSettlementSouvenirRequest(Souvenir); return(true); } catch { return(false); } }
public void CloseSettlementSouvenirRequest(SouvenirStockViewModel Souvenir) { using (MarcommEntities db = new MarcommEntities()) { var souvenir = (from p in db.t_souvenir where p.id.Equals(Souvenir.id) select p).SingleOrDefault(); souvenir.status = 6; souvenir.update_by = Souvenir.updateBy; souvenir.update_date = DateTime.Now; db.Entry(souvenir).State = EntityState.Modified; db.SaveChanges(); } }
public void ApprovalSettlementSouvenirRequest(SouvenirStockViewModel Souvenir) { using (MarcommEntities db = new MarcommEntities()) { var souvenir = (from p in db.t_souvenir where p.id.Equals(Souvenir.id) select p).SingleOrDefault(); souvenir.status = Souvenir.status; souvenir.settlement_approved_by = Souvenir.settlementApprovedBy; souvenir.settlement_approved_date = Souvenir.settlementApprovedDate; souvenir.reject_reason = Souvenir.rejectReason; souvenir.update_by = Souvenir.updateBy; souvenir.update_date = DateTime.Now; db.Entry(souvenir).State = EntityState.Modified; db.SaveChanges(); } }
public ActionResult Edit(int id) { UserViewModel result = UserRepo.GetIdByName(User.Identity.Name); ViewBag.Employee = new SelectList(EmployeeRepo.Get(), "Id", "First_Name"); SouvenirStockViewModel model = SouvenirStockRepo.GetById(id); if (result.Role == "Staff" || result.Role == "Admin") { return(PartialView("_Edit", model)); } else { return(new RedirectToRouteResult(new RouteValueDictionary(new { controller = "AccessDenied", action = "Index" }))); } }
public static List <SouvenirStockViewModel> Filter(SouvenirStockViewModel entity) { List <SouvenirStockViewModel> result = new List <SouvenirStockViewModel>(); using (var db = new MarComContext()) { result = (from ss in db.T_Souvenir where ss.Code.Contains(entity.Code) || ss.Received_By == entity.Received_By || (ss.Received_Date.ToString()).Contains(entity.Received_Date.ToString()) || (ss.Create_Date.ToString()).Contains(entity.Create_Date.ToString()) || ss.Create_By.Contains(entity.Create_By) where ss.Status == null select new SouvenirStockViewModel { Code = ss.Code, Received_By = ss.Received_By, Received_Date = ss.Received_Date, Create_Date = ss.Create_Date, Create_By = ss.Create_By }).ToList(); } return(result); }
public ActionResult Add(SouvenirStockViewModel model, List <SouvenirItemViewModel> item) { if (ModelState.IsValid) { model.Create_By = User.Identity.Name; ResultResponse result = SouvenirStockRepo.Update(model, item); return(Json(new { success = result.Success, entity = model, message = result.Message }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "wew" }, JsonRequestBehavior.AllowGet)); } }
public static SouvenirStockViewModel GetById(int id) { SouvenirStockViewModel result = new SouvenirStockViewModel(); using (var db = new MarComContext()) { result = (from ts in db.T_Souvenir join em in db.M_Employee on ts.Received_By equals em.Id where ts.Id == id select new SouvenirStockViewModel { Id = ts.Id, Code = ts.Code, Received_By = em.Id, R_Name = em.First_Name + " " + em.Last_Name, Received_Date = ts.Received_Date, Note = ts.Note }).FirstOrDefault(); } return(result); }
public ActionResult Filter(SouvenirStockViewModel model) { return(PartialView("_List", SouvenirStockRepo.Filter(model))); }
public ActionResult Details(int id) { SouvenirStockViewModel model = SouvenirStockRepo.GetById(id); return(PartialView("_Details", model)); }
public static ResultResponse Update(SouvenirStockViewModel entity, List <SouvenirItemViewModel> entityitem) { ResultResponse result = new ResultResponse(); try { using (var db = new MarComContext()) { if (entity.Id == 0) { T_Souvenir tsouv = new T_Souvenir(); tsouv.Code = entity.Code; tsouv.Type = "Additional"; tsouv.Received_By = entity.Received_By; tsouv.Received_Date = entity.Received_Date; tsouv.Note = entity.Note; tsouv.Create_By = entity.Create_By; tsouv.Create_Date = DateTime.Now; db.T_Souvenir.Add(tsouv); foreach (var item in entityitem) { T_Souvenir_Item tsouvItem = new T_Souvenir_Item(); tsouvItem.T_Souvenir_Id = entity.Id; tsouvItem.M_Souvenir_Id = item.M_Souvenir_Id; tsouvItem.Qty = item.Qty; tsouvItem.Note = item.Note; tsouvItem.Is_Delete = item.Is_Delete; tsouvItem.Create_By = entity.Create_By; tsouvItem.Create_Date = DateTime.Now; db.T_Souvenir_Item.Add(tsouvItem); } db.SaveChanges(); } else { T_Souvenir tsouv = db.T_Souvenir.Where(ts => ts.Id == entity.Id).FirstOrDefault(); if (tsouv != null) { tsouv.Code = entity.Code; tsouv.Type = "Additional"; tsouv.Received_By = entity.Received_By; tsouv.Received_Date = entity.Received_Date; tsouv.Note = entity.Note; tsouv.Update_By = entity.Update_By; tsouv.Update_Date = DateTime.Now; foreach (var item in entityitem) { T_Souvenir_Item tsouvItem = new T_Souvenir_Item(); tsouvItem.T_Souvenir_Id = entity.Id; tsouvItem.M_Souvenir_Id = item.M_Souvenir_Id; tsouvItem.Qty = item.Qty; tsouvItem.Note = item.Note; tsouvItem.Is_Delete = item.Is_Delete; if (item.Id == 0) { tsouvItem.Create_By = entity.Update_By; tsouvItem.Create_Date = DateTime.Now; } else { tsouvItem.Update_By = entity.Update_By; tsouvItem.Update_Date = DateTime.Now; } db.T_Souvenir_Item.Add(tsouvItem); } db.SaveChanges(); } } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }