public List <DTO.HistoryDTO> GetHistoryData(int userId, int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification { Type = Library.DTO.NotificationType.Success }; List <DTO.HistoryDTO> data = new List <DTO.HistoryDTO>(); try { using (EstimatedPurchasingPriceMngEntities context = CreateContext()) { data = converter.DB2DTO_HistoryDTO(context.EstimatedPurchasingPriceMng_History_View.Where(o => o.EstimatedPurchasingPriceID == id).OrderByDescending(o => o.UpdatedDate).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(data); }
public DTO.SupportFormData GetFactories(int userId, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification { Type = Library.DTO.NotificationType.Success }; DTO.SupportFormData data = new DTO.SupportFormData(); data.FactoryDTOs = new List <DTO.FactoryDTO>(); try { using (EstimatedPurchasingPriceMngEntities context = CreateContext()) { data.FactoryDTOs = converter.DB2DTO_Factory(context.EstimatedPurchasingPriceMng_function_GetAuthorizedFactory(userId).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(data); }
public bool UpdateData(int userId, object dtoInputItems, out Library.DTO.Notification notification) { List <DTO.EstimatedPurchasingPriceSearchResultDTO> dtoItems = ((Newtonsoft.Json.Linq.JArray)dtoInputItems).ToObject <List <DTO.EstimatedPurchasingPriceSearchResultDTO> >(); notification = new Library.DTO.Notification { Type = Library.DTO.NotificationType.Success }; try { using (EstimatedPurchasingPriceMngEntities context = CreateContext()) { EstimatedPurchasingPrice dbNewItem; EstimatedPurchasingPriceHistory dbNewHistory; foreach (DTO.EstimatedPurchasingPriceSearchResultDTO dtoItem in dtoItems.Where(o => o.EstimatedPurchasingPriceID <= 0).ToList()) { dbNewItem = new EstimatedPurchasingPrice(); context.EstimatedPurchasingPrice.Add(dbNewItem); converter.DTO2DB(dtoItem, ref dbNewItem); dbNewItem.EstimatedPrice = dtoItem.NewEstimatedPrice; dbNewItem.Remark = dtoItem.NewRemark; dbNewItem.UpdatedBy = userId; dbNewItem.UpdatedDate = DateTime.Now; // add history dbNewHistory = new EstimatedPurchasingPriceHistory { EstimatedPrice = dtoItem.NewEstimatedPrice, Remark = dtoItem.NewRemark, UpdatedBy = userId, UpdatedDate = DateTime.Now }; dbNewItem.EstimatedPurchasingPriceHistory.Add(dbNewHistory); } var toBeUpdatedDTOs = dtoItems.Where(o => o.EstimatedPurchasingPriceID > 0 && (o.NewEstimatedPrice.HasValue || !string.IsNullOrEmpty(o.NewRemark))).ToList(); var toBeUpdatedDTOIDS = toBeUpdatedDTOs.Select(o => o.EstimatedPurchasingPriceID).ToList(); foreach (EstimatedPurchasingPrice dbItem in context.EstimatedPurchasingPrice.Where(o => toBeUpdatedDTOIDS.Contains(o.EstimatedPurchasingPriceID)).ToList()) { dbItem.EstimatedPrice = toBeUpdatedDTOs.FirstOrDefault(o => o.EstimatedPurchasingPriceID == dbItem.EstimatedPurchasingPriceID).NewEstimatedPrice; dbItem.Remark = toBeUpdatedDTOs.FirstOrDefault(o => o.EstimatedPurchasingPriceID == dbItem.EstimatedPurchasingPriceID).NewRemark; dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; // add history dbNewHistory = new EstimatedPurchasingPriceHistory { EstimatedPrice = dbItem.EstimatedPrice, Remark = dbItem.Remark, UpdatedBy = userId, UpdatedDate = DateTime.Now }; dbItem.EstimatedPurchasingPriceHistory.Add(dbNewHistory); } context.SaveChanges(); return(true); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } return(false); }
public override DTO.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.SearchFormData data = new DTO.SearchFormData(); data.Data = new List <DTO.EstimatedPurchasingPriceSearchResultDTO>(); totalRows = 0; string Season = null; string Remark = null; string OfferUD = null; string FactoryUD = null; string PackagingMethodNM = null; string Description = null; int UserID = 0; if (filters.ContainsKey("Season") && filters["Season"] != null && !string.IsNullOrEmpty(filters["Season"].ToString())) { Season = filters["Season"].ToString().Replace("'", "''"); } if (filters.ContainsKey("OfferUD") && !string.IsNullOrEmpty(filters["OfferUD"].ToString())) { OfferUD = filters["OfferUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("Remark") && !string.IsNullOrEmpty(filters["Remark"].ToString())) { Remark = filters["Remark"].ToString().Replace("'", "''"); } if (filters.ContainsKey("FactoryUD") && !string.IsNullOrEmpty(filters["FactoryUD"].ToString())) { FactoryUD = filters["FactoryUD"].ToString().Replace("'", "''"); } if (filters.ContainsKey("PackagingMethodNM") && !string.IsNullOrEmpty(filters["PackagingMethodNM"].ToString())) { PackagingMethodNM = filters["PackagingMethodNM"].ToString().Replace("'", "''"); } if (filters.ContainsKey("Description") && !string.IsNullOrEmpty(filters["Description"].ToString())) { Description = filters["Description"].ToString().Replace("'", "''"); } if (filters.ContainsKey("UserID") && filters["UserID"] != null && !string.IsNullOrEmpty(filters["UserID"].ToString())) { UserID = Convert.ToInt32(filters["UserID"].ToString()); } //try to get data try { using (EstimatedPurchasingPriceMngEntities context = CreateContext()) { var result = context.EstimatedPurchasingPriceMng_function_SearchEstimatedPurchasingPrice(Season, Remark, FactoryUD, Description, PackagingMethodNM, OfferUD, UserID, orderBy, orderDirection).ToList(); totalRows = result.Count(); data.Data = converter.DB2DTO_EstimatedPurchasingPriceSearchResult(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }