Esempio n. 1
0
        public override DTO.SearchFormData GetDataWithFilter(int userId, System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            DTO.SearchFormData searchFormData = new DTO.SearchFormData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            totalRows = 0;
            try
            {
                string productionItemUD   = null;
                string productionItemNM   = null;
                string productionItemNMEN = null;
                int?   companyID          = fw_factory.GetCompanyID(userId);

                if (filters.ContainsKey("productionItemUD") && !string.IsNullOrEmpty(filters["productionItemUD"].ToString()))
                {
                    productionItemUD = filters["productionItemUD"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("productionItemNM") && !string.IsNullOrEmpty(filters["productionItemNM"].ToString()))
                {
                    productionItemNM = filters["productionItemNM"].ToString().Replace("'", "''");
                }
                if (filters.ContainsKey("productionItemNMEN") && !string.IsNullOrEmpty(filters["productionItemNMEN"].ToString()))
                {
                    productionItemNMEN = filters["productionItemNMEN"].ToString().Replace("'", "''");
                }
                using (BreakdownPriceListMngEntities context = CreateContext())
                {
                    totalRows = context.BreakdownPriceListMng_function_SearchBreakdownPriceList(orderBy, orderDirection, productionItemUD, productionItemNM, productionItemNMEN).Count();
                    var result = context.BreakdownPriceListMng_function_SearchBreakdownPriceList(orderBy, orderDirection, productionItemUD, productionItemNM, productionItemNMEN);
                    searchFormData.Data      = converter.DB2DTO_Search(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                    searchFormData.CompanyID = companyID.Value;

                    //get exchange rate of USD
                    var dbExchangeRate = context.BreakdownPriceListMng_function_GetExchangeRate(DateTime.Now, "USD").FirstOrDefault();
                    if (dbExchangeRate != null)
                    {
                        searchFormData.ExchangeRate = dbExchangeRate.ExchangeRate;
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
            }
            return(searchFormData);
        }
        public bool UpdatePrice(int userId, object priceListTable, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success, Message = "Update Price Success"
            };
            List <DTO.BreakdownPriceListSearchDTO> dtoPriceList = ((Newtonsoft.Json.Linq.JArray)priceListTable).ToObject <List <DTO.BreakdownPriceListSearchDTO> >();

            try
            {
                using (BreakdownPriceListMngEntities context = CreateContext())
                {
                    int?        companyID         = fw_factory.GetCompanyID(userId);
                    List <int?> productionItemIDs = dtoPriceList.Select(o => o.ProductionItemID).ToList();
                    var         dbPrice           = context.BreakdownPriceList.Where(o => productionItemIDs.Contains(o.ProductionItemID) && o.CompanyID == companyID).ToList();
                    foreach (var item in dbPrice)
                    {
                        var dtoPriceItem = dtoPriceList.Where(o => o.ProductionItemID == item.ProductionItemID).FirstOrDefault();
                        if (dtoPriceItem != null)
                        {
                            if (companyID == 1) //AuvietFur Price
                            {
                                item.UnitPrice = dtoPriceItem.AVFPrice;
                            }
                            else if (companyID == 3) //AnVietThinh Price
                            {
                                item.UnitPrice = dtoPriceItem.AVTPrice;
                            }
                            item.UpdatedBy   = userId;
                            item.UpdatedDate = DateTime.Now;
                        }
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
                return(false);
            }
            return(true);
        }
 public bool AddProductionItemPrice(out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success, Message = "Add product item price success"
     };
     try
     {
         using (BreakdownPriceListMngEntities context = CreateContext())
         {
             context.BreakdownPriceListMng_function_AddProductionItemPrice();
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = Library.Helper.GetInnerException(ex).Message;
         return(false);
     }
     return(true);
 }