Ejemplo n.º 1
0
 partial void UpdateCustomerPricing(CustomerPricing instance);
Ejemplo n.º 2
0
 partial void DeleteCustomerPricing(CustomerPricing instance);
Ejemplo n.º 3
0
		private void detach_CustomerPricings(CustomerPricing entity)
		{
			this.SendPropertyChanging();
			entity.Customer = null;
		}
Ejemplo n.º 4
0
 partial void InsertCustomerPricing(CustomerPricing instance);
Ejemplo n.º 5
0
        public void SetPrice(string key = "")
        {
            try {
                int customerID = Convert.ToInt32(Request.Form["customerID"]);
                int partID = Convert.ToInt32(Request.Form["partID"]);
                decimal price = Convert.ToDecimal(Request.Form["price"]);
                int isSale = (Request.Form["isSale"] != null && Request.Form["isSale"] != "") ? Convert.ToInt32(Request.Form["isSale"]) : 0;
                string sale_start = (Request.Form["sale_start"] != null) ? Request.Form["sale_start"].Trim() : "";
                string sale_end = (Request.Form["sale_end"] != null) ? Request.Form["sale_end"].Trim() : "";

                CustomerPricing pricing = new CustomerPricing{
                    cust_id = customerID,
                    partID = partID,
                    price = price,
                    isSale = isSale,
                    sale_start = (sale_start.Length > 0) ? Convert.ToDateTime(sale_start) : (DateTime?)null,
                    sale_end = (sale_end.Length > 0) ? Convert.ToDateTime(sale_end) : (DateTime?)null
                };

                SimplePricing simpleprice = pricing.Set(key);

                Response.ContentType = "application/json";
                Response.Write(JsonConvert.SerializeObject(simpleprice));
                Response.End();
            } catch (Exception e) {
                //Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                //Response.StatusDescription = e.Message;
                Response.ContentType = "application/json";
                Response.Write(JsonConvert.SerializeObject(e.Message + " " + e.StackTrace,Formatting.Indented));
                Response.End();
            }
        }
Ejemplo n.º 6
0
 /********* Customer Interaction *********/
 public void GetPricing(int customerID = 0, string key = "")
 {
     try {
         CustomerPricing pricing = new CustomerPricing { cust_id = customerID };
         Response.ContentType = "application/json";
         Response.Write(JsonConvert.SerializeObject(pricing.GetAll(key)));
         Response.End();
     } catch (Exception e) {
         Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
         Response.StatusDescription = e.Message;
         Response.ContentType = "application/json";
         Response.Write(JsonConvert.SerializeObject(e.Message, Formatting.Indented));
         Response.End();
     }
 }
Ejemplo n.º 7
0
        public void SetCustomerPartAndPrice(int customerID = 0, string key = "", int partID = 0,  int customerPartID = 0, decimal price = 0, int isSale = 0, string sale_start = "", string sale_end = "")
        {
            try {
                CartIntegration integration = new CartIntegration {
                    custID = customerID,
                    custPartID = customerPartID,
                    partID = partID
                };
                CartIntegration newintegration = integration.Set(key);
                CustomerPricing pricing = new CustomerPricing {
                    cust_id = customerID,
                    partID = partID,
                    price = price,
                    isSale = isSale,
                    sale_start = (sale_start.Length > 0) ? Convert.ToDateTime(sale_start) : (DateTime?)null,
                    sale_end = (sale_end.Length > 0) ? Convert.ToDateTime(sale_end) : (DateTime?)null
                };
                SimplePricing newpricing = pricing.Set(key);
                List<object> results = new List<object>();
                results.Add(newintegration);
                results.Add(newpricing);

                Response.ContentType = "application/json";
                Response.Write(JsonConvert.SerializeObject(results));
                Response.End();
            } catch (Exception e) {
                //Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                //Response.StatusDescription = e.Message;
                Response.ContentType = "application/json";
                Response.Write(JsonConvert.SerializeObject(e.Message, Formatting.Indented));
                Response.End();
            }
        }
Ejemplo n.º 8
0
 public void ResetToMap(string key = "", int customerID = 0, int partID = 0)
 {
     try {
         CustomerPricing pricing = new CustomerPricing {
             cust_id = customerID,
             partID = partID
         };
         Response.ContentType = "application/json";
         Response.Write(JsonConvert.SerializeObject(pricing.SetToMap(key)));
     } catch (Exception e) {
         Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
         Response.StatusDescription = e.Message;
         Response.ContentType = "application/json";
         Response.Write(JsonConvert.SerializeObject(e.Message + e.StackTrace, Formatting.Indented));
         Response.End();
     }
 }
Ejemplo n.º 9
0
 public void RemoveSale(string key = "", int customerID = 0, int partID = 0, decimal price = 0)
 {
     try {
         CustomerPricing pricing = new CustomerPricing {
             cust_id = customerID,
             partID = partID,
             price = price,
             isSale = 1
         };
         pricing.RemoveSale(key);
         Response.ContentType = "application/json";
         Response.Write("");
         Response.End();
     } catch (Exception e) {
         Response.ContentType = "application/json";
         Response.Write(JsonConvert.SerializeObject(e.Message, Formatting.Indented));
         Response.End();
     }
 }
Ejemplo n.º 10
0
 public void PriceUpload(string key = "", int customerID = 0)
 {
     try {
         if (key == "") {
             throw new Exception("Key is missing and is required");
         }
         if (customerID == 0) {
             throw new Exception("Customer ID is missing and is required");
         }
         StreamReader reader = new StreamReader(Request.InputStream);
         string pricedata = reader.ReadToEnd();
         List<string> rows = pricedata.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
         Parallel.ForEach(rows, currentRow => {
             try {
                 List<string> fields = currentRow.Split(',').ToList();
                 int partID = Convert.ToInt32(fields[0]);
                 int CustomerPartID = (fields[1].Trim() != "") ? Convert.ToInt32(fields[1]) : 0;
                 decimal price = (fields[2].Trim() != "") ? Convert.ToDecimal(fields[2]) : 0;
                 string sale_start = fields[3].Trim();
                 string sale_end = fields[4].Trim();
                 int isSale = (sale_start != "") ? 1 : 0;
                 CustomerPricing pricing = new CustomerPricing {
                     cust_id = customerID,
                     partID = partID,
                     price = price,
                     isSale = isSale,
                     sale_start = (sale_start.Length > 0) ? Convert.ToDateTime(sale_start) : (DateTime?)null,
                     sale_end = (sale_end.Length > 0) ? Convert.ToDateTime(sale_end) : (DateTime?)null
                 };
                 try {
                     pricing.Set(key);
                 } catch { }
                 CartIntegration integration = new CartIntegration {
                     custID = customerID,
                     custPartID = CustomerPartID,
                     partID = partID
                 };
                 try {
                     integration.Set(key);
                 } catch { }
             } catch {}
         });
         Response.ContentType = "application/json";
         Response.Write(JsonConvert.SerializeObject("uploading", Formatting.Indented));
         Response.End();
     } catch (Exception e) {
         Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
         Response.StatusDescription = e.Message;
         Response.ContentType = "application/json";
         Response.Write(JsonConvert.SerializeObject(e.Message, Formatting.Indented));
         Response.End();
     }
 }
Ejemplo n.º 11
0
        public SimplePricing Set(string key)
        {
            Authenticate(key);
            CurtDevDataContext db = new CurtDevDataContext();

            // Validate required fields
            if (this.price == 0) { throw new Exception("Price failed to validate against null or zero."); }
            if (this.partID == 0) { throw new Exception("Part Number failed to validate against null or zero."); }
            if (this.isSale == 1) {
                if (this.sale_start == null || this.sale_start < DateTime.Today.AddDays(-1)) { throw new Exception("If record is going to marked as sale, sale start is required and cannot be in the past."); }
                if (this.sale_end == null || this.sale_end < DateTime.Now || this.sale_end <= this.sale_start) { throw new Exception("If record is going to marked as sale, sale end is required, cannot be in the past, and cannot be sooner or equal to the sale start."); }
            } else {
                this.sale_start = null;
                this.sale_end = null;
            }

            // Make sure the price point isn't set lower than map
            if (!checkMap()) {
                throw new Exception("You may not set the price point lower than map price.");
            }
            CustomerPricing newpricing = new CustomerPricing {
                cust_id = this.cust_id,
                partID = this.partID,
                price = this.price,
                isSale = this.isSale,
                sale_start = this.sale_start,
                sale_end = this.sale_end
            };

            // Attempt to get a CustomerPricing record for this customerID and partID
            List<CustomerPricing> tmpPoints = db.CustomerPricings.Where(x => x.cust_id.Equals(this.cust_id) && x.partID.Equals(this.partID)).ToList<CustomerPricing>();
            bool updated = false;
            List<CustomerPricing> deletables = new List<CustomerPricing>();
            foreach (CustomerPricing tmpPoint in tmpPoints) {
                bool deleted = false;
                if (tmpPoint.sale_end != null && tmpPoint.sale_end < DateTime.Now) {
                    // expired sale - delete
                    deletables.Add(tmpPoint);
                    deleted = true;
                }
                if (!deleted && this.isSale == tmpPoint.isSale) {
                    if (!updated) {
                        tmpPoint.price = this.price;
                        tmpPoint.isSale = this.isSale;
                        tmpPoint.sale_start = this.sale_start;
                        tmpPoint.sale_end = this.sale_end;
                        newpricing.cust_price_id = tmpPoint.cust_price_id;
                        updated = true;
                    } else {
                        deletables.Add(tmpPoint);
                    }
                }
            }
            if (!updated) {
                db.CustomerPricings.InsertOnSubmit(newpricing);
            }
            if (deletables.Count > 0) {
                db.CustomerPricings.DeleteAllOnSubmit(deletables);
            }
            db.SubmitChanges();

            CustomerPricing currentPrice = db.CustomerPricings.Where(x => x.cust_price_id.Equals(newpricing.cust_price_id)).FirstOrDefault<CustomerPricing>();

            SimplePricing pricePoint = new SimplePricing {
                cust_id = currentPrice.cust_id,
                partID = currentPrice.partID,
                price = currentPrice.price,
                isSale = currentPrice.isSale,
                sale_start = currentPrice.sale_start.ToString(),
                sale_end = currentPrice.sale_end.ToString()
            };
            return pricePoint;
        }