Exemple #1
0
        public virtual ActionResult Save(DispatchTable dispatch)
        {
            int resultado = 0;

            try
            {
                if (dispatch.DispatchID > 0)
                {
                    using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required))
                    {
                        resultado = Dispatch.UpdateDispatch(dispatch);
                        if (resultado < 1)
                        {
                            tran.Dispose();
                            return(Json(new { result = false, message = "No se grabó correctamente en la tabla Dispatch" }));
                        }

                        int retora = DispatchItems.DeleteDispatchItemsbyID(dispatch.DispatchID);

                        foreach (var product in dispatch.Products.Where(x => x.ProductID != 0))
                        {
                            product.DispatchID = dispatch.DispatchID;

                            if (DispatchItems.InsertDispatchItems(product) < 1)
                            {
                                tran.Dispose();
                                return(Json(new { result = false, message = "No se grabó correctamente en la tabla Dispatch" }));
                            }
                        }
                        resultado = 1;
                        tran.Complete();
                    }
                }
                else
                {
                    using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required))
                    {
                        int dispatchID = 0;
                        dispatchID = Dispatch.InsertDispatch(dispatch);
                        if (dispatchID < 1)
                        {
                            tran.Dispose();
                            return(Json(new { result = false, message = "No se grabó correctamente en la tabla Dispatch" }));
                        }
                        foreach (var product in dispatch.Products.Where(x => x.ProductID != 0))
                        {
                            product.DispatchID = dispatchID;

                            if (DispatchItems.InsertDispatchItems(product) < 1)
                            {
                                tran.Dispose();
                                return(Json(new { result = false, message = "No se grabó correctamente en la tabla Dispatch" }));
                            }
                        }
                        resultado = 1;
                        tran.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                var exception = EntityExceptionHelper.GetAndLogNetStepsException(ex, NetSteps.Data.Entities.Constants.NetStepsExceptionType.NetStepsApplicationException);
                //tran.Dispose();
                //throw exception;
                return(Json(new { result = false, message = ex.Message }));
            }
            return(Json(new { result = (resultado == 0 ? false : true), message = "" }));
        }