public virtual async Task <Output <SalesOrder_UpdateOutput> > UpdateAsync(int _salesOrderId, SalesOrder_UpdateInput_Data _data)
        {
            SalesOrder_UpdateOutput res = new SalesOrder_UpdateOutput();

            try
            {
                currentErrors.AbortIfHasErrors();

                // CUSTOM_CODE_START: add custom security checks for Update operation below
                // CUSTOM_CODE_END
                SalesOrder obj = await ctx.FindEntityAsync <SalesOrder>(currentErrors, _salesOrderId);

                var entry = ctx.Entry(obj);
                entry.CurrentValues.SetValues(_data);
                // CUSTOM_CODE_START: use the Customer input parameter of Update operation below
                await UpdateCustomer(obj, _data.Customer); // CUSTOM_CODE_END

                // CUSTOM_CODE_START: use the Payment input parameter of Update operation below
                await UpdatePayment(obj, _data.Payment); // CUSTOM_CODE_END

                // CUSTOM_CODE_START: use the Sales input parameter of Update operation below
                await UpdateSalesInfo(obj, _data.Sales); // CUSTOM_CODE_END

                // CUSTOM_CODE_START: add custom code for Update operation below
                obj.ModifiedDate = DateTime.Now;
                // CUSTOM_CODE_END
                currentErrors.AbortIfHasErrors();
                await ctx.SaveChangesAsync();

                ServiceUtil.CopyProperties(obj, res);
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorParser.FromException(ex));
            }
            return(await Task.FromResult(new Output <SalesOrder_UpdateOutput>(currentErrors, res)));
        }
Ejemplo n.º 2
0
 protected void UpdateSalesInfo(SalesOrder obj, SalesInfo _data)
 {
     if (_data == null)
     {
         currentErrors.AddValidationError(Messages.SalesRequired, obj.SalesOrderId);
         return;
     }
     obj.TerritoryObject   = ctx.FindEntity <SalesTerritory>(currentErrors, _data.TerritoryId);
     obj.SalesPersonObject = ctx.Find <SalesPerson>(currentErrors, _data.SalesPersonId);
     // remove sales reason that are not in the provided list
     obj.ReasonObjectList.Where(r => _data.SalesReason == null || !_data.SalesReason.Contains(r.SalesReasonId))
     .ToList().ForEach(r => obj.ReasonObjectList.Remove(r));
     if (_data.SalesReason != null)
     {
         // add sales reasons from provided list that don't exist yet
         _data.SalesReason.Where(rId => obj.ReasonObjectList.Where(r => r.SalesReasonId == rId).ToList().Count == 0)
         .ToList().ForEach(rId => obj.ReasonObjectList.Add(new SalesOrderReason()
         {
             SalesOrderId  = obj.SalesOrderId,
             SalesReasonId = rId,
             ModifiedDate  = DateTime.Now
         }));
     }
 }
        public virtual async Task <Output> DeleteAsync(int _salesOrderId)
        {
            try
            {
                currentErrors.AbortIfHasErrors();

                // CUSTOM_CODE_START: add custom security checks for Delete operation below
                // CUSTOM_CODE_END
                EntityState state = EntityState.Deleted;
                SalesOrder  obj   = await ctx.FindEntityAsync <SalesOrder>(currentErrors, _salesOrderId);

                var entry = ctx.Entry(obj);
                entry.State = state;
                // CUSTOM_CODE_START: add custom code for Delete operation below
                // CUSTOM_CODE_END
                currentErrors.AbortIfHasErrors();
                await ctx.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorParser.FromException(ex));
            }
            return(await Task.FromResult(new Output(currentErrors)));
        }