Exemplo n.º 1
0
        public JsonResult updateFeeRepository([FromBody] Business.FeeDataModel request)
        {
            var  respuesta = new { idEntity = request.FeeID, idEntityRequest = request.FeeID, message = "OK", error = "", DataReceived = request, OldData = "" };
            Fees oldData   = null;

            using (QuotingToolRepository db = new QuotingToolRepository())
            {
                try
                {
                    var FeeData = request.FeeID > 0 ? db.Fees.Where(i => i.FeeID == request.FeeID).Single() : new Fees();
                    oldData = FeeData;
                    if (request.FeeID > 0)
                    {
                        FeeData.DateUpdated = System.DateTime.Now;
                        FeeData.UpdatedBy   = "SYSTEM"; // Replace with the right identity,
                    }
                    else
                    {
                        FeeData.DateAdded = System.DateTime.Now;
                        FeeData.AddedBy   = "SYSTEM"; // Replace with the right identity,
                    }

                    FeeData.FeeID       = request.FeeID;
                    FeeData.ParentFeeID = request.ParentFeeID;
                    FeeData.FeeTypeID   = request.FeeTypeID;
                    FeeData.ByUomID     = request.ByUomID;
                    FeeData.CityID      = request.CityID;
                    FeeData.StateID     = request.StateID;
                    FeeData.Discount    = request.Discount;
                    FeeData.IslandID    = request.IslandID;
                    FeeData.ActionID    = request.ActionID;
                    FeeData.Value       = request.Value;
                    FeeData.ZipCodes    = request.ZipCodes;
                    FeeData.FeeMin      = request.FeeMin;
                    FeeData.FeeMax      = request.FeeMax;
                    FeeData.RangeFrom   = request.RangeFrom;
                    FeeData.RangeTo     = request.RangeTo;
                    FeeData.ValidFrom   = request.ValidFrom;
                    FeeData.ValidUntil  = request.ValidUntil;

                    if (request.FeeID < 0 && Helpers.NewEntityCreationHelper.CheckMandatoryFields(FeeData, typeof(Fees)))
                    {
                        db.Fees.AddObject(FeeData);
                    }

                    if (db.SaveChanges() > 0)
                    {
                        respuesta = new { idEntity = FeeData.FeeID, idEntityRequest = request.FeeID, message = "OK", error = "", DataReceived = request, OldData = JsonConvert.SerializeObject(oldData) }
                    }
                    ;
                }
                catch (Exception ex)
                {
                    Response.StatusCode = 500;
                    respuesta           = new { idEntity = request.FeeID, idEntityRequest = request.FeeID, message = "ERROR", error = ex.Message, DataReceived = request, OldData = JsonConvert.SerializeObject(oldData) };
                }
            }

            return(Json(respuesta, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult updateSingleFieldFeeData([FromBody] Business.AGCellValueDataChangedModel request)
        {
            var  respuesta = new { idEntity = request.idEntity, message = "OK", error = "", DataReceived = request, OldData = "" };
            Fees oldData   = null;

            using (QuotingToolRepository db = new QuotingToolRepository())
            {
                try
                {
                    var FeeData = request.idEntity > -1 ? db.Fees.Where(i => i.FeeID == request.idEntity).Single() : new Fees();
                    oldData = FeeData;
                    if (request.idEntity > -1)
                    {
                        FeeData.DateUpdated = System.DateTime.Now;
                        FeeData.UpdatedBy   = "System"; // Replace with the right identity,
                    }
                    else
                    {
                        FeeData.DateAdded = System.DateTime.Now;
                        FeeData.AddedBy   = "System"; // Replace with the right identity,
                    }

                    var properties = typeof(Fees).GetProperties(BindingFlags.Public | BindingFlags.Instance);
                    foreach (var property in properties)
                    {
                        if (request.field == property.Name)
                        {
                            property.SetValue(FeeData, Helpers.TypesHelper.ChangeType(request.newValue, property.PropertyType), null);
                            break;
                        }
                    }

                    if (request.idEntity == -1)
                    {
                        db.Fees.AddObject(FeeData);
                    }

                    if (db.SaveChanges() > 0)
                    {
                        respuesta = new { idEntity = request.idEntity, message = "OK", error = "", DataReceived = request, OldData = JsonConvert.SerializeObject(oldData) }
                    }
                    ;
                }
                catch (Exception ex)
                {
                    Response.StatusCode = 500;
                    respuesta           = new { idEntity = request.idEntity, message = "ERROR", error = ex.Message + System.Environment.NewLine + ex.InnerException?.Message, DataReceived = request, OldData = JsonConvert.SerializeObject(oldData) };
                }
            }

            return(Json(respuesta, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public JsonResult removeFeeData([FromBody] int[] ids)
        {
            var respuesta = new { message = "OK", error = "", DataReceived = JsonConvert.SerializeObject(ids), OldData = "" };

            try
            {
                using (QuotingToolRepository db = new QuotingToolRepository())
                {
                    foreach (int id in ids)
                    {
                        db.Fees.DeleteObject(db.Fees.Where(i => i.FeeID == id).Single());
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                respuesta           = new { message = "ERROR", error = ex.Message, DataReceived = JsonConvert.SerializeObject(ids), OldData = "" };
            }
            return(Json(respuesta, JsonRequestBehavior.AllowGet));
        }