Пример #1
0
        public ResponseBase Update(OrderInfo_Product Product)
        {
            ResponseBase response = new ResponseBase();

            try
            {
                using (var ctx = new SimpleCureEntities())
                {
                    ctx.Entry(Product).State = System.Data.Entity.EntityState.Modified;
                    var updated = ctx.SaveChanges();

                    if (updated > 0)
                    {
                        response.ResponseSuccess = true;
                        response.ResponseInt     = Product.ID;
                    }
                    else
                    {
                        response.ResponseMessage = "Unable to update Product Order Info for Product: " + Product;
                    }
                }
            }
            catch (Exception ex)
            {
                string obj          = JsonConvert.SerializeObject(Product);
                string methodName   = System.Reflection.MethodBase.GetCurrentMethod().Name;
                string source       = ex.Source;
                string stacktrace   = ex.StackTrace;
                string targetsite   = ex.TargetSite.ToString();
                string error        = ex.InnerException.ToString();
                string ErrorMessage = $"There was an error at {DateTime.Now} {Environment.NewLine} Method: {methodName} {Environment.NewLine} Source: {source} {Environment.NewLine} StackTrace: {stacktrace} {Environment.NewLine} TargetSite: {targetsite} {Environment.NewLine} Error: {error}{Environment.NewLine} Object: {obj}";
                _applicationError.Log(ErrorMessage, string.Empty);

                response.ResponseMessage = "Unable to update Product Order Info for Product: " + Product;
            }

            return(response);
        }
Пример #2
0
        public ResponseBase Add(OrderInfo_Product Product)
        {
            ResponseBase response = new ResponseBase();

            try
            {
                using (var ctx = new SimpleCureEntities())
                {
                    var Added = ctx.OrderInfo_Product.Add(Product);

                    if (Added.ID > 0)
                    {
                        response.ResponseSuccess = true;
                        //confirm if this is needed or not
                        _emailMessage.SendMessage(ConfigurationManager.AppSettings["EmailAddress"], "Product added to Order", "A product has been added to a order.");
                    }
                    else
                    {
                        response.ResponseMessage = "Unable to add Products to Order with Product Info: " + Product;
                    }
                }
            }
            catch (Exception ex)
            {
                string obj          = JsonConvert.SerializeObject(Product);
                string methodName   = System.Reflection.MethodBase.GetCurrentMethod().Name;
                string source       = ex.Source;
                string stacktrace   = ex.StackTrace;
                string targetsite   = ex.TargetSite.ToString();
                string error        = ex.InnerException.ToString();
                string ErrorMessage = $"There was an error at {DateTime.Now} {Environment.NewLine} Method: {methodName} {Environment.NewLine} Source: {source} {Environment.NewLine} StackTrace: {stacktrace} {Environment.NewLine} TargetSite: {targetsite} {Environment.NewLine} Error: {error}{Environment.NewLine} Object: {obj}";
                _applicationError.Log(ErrorMessage, string.Empty);

                response.ResponseMessage = "Unable to add Products to Order with Product Info: " + Product;
            }

            return(response);
        }