public async Task CreateAsync(WayOfException wayOfExceptionToAdd)
        {
            Stopwatch timespan = Stopwatch.StartNew();

            try
            {
                db.WayOfExceptions.Add(wayOfExceptionToAdd);
                await db.SaveChangesAsync();

                timespan.Stop();
                log.TraceApi("SQL Database", "WayOfExceptionRepository.CreateAsync", timespan.Elapsed, "wayOfExceptionToAdd={0}", wayOfExceptionToAdd);
            }
            catch (Exception e)
            {
                log.Error(e, "Error in WayOfExceptionRepository.CreateAsync(wayOfExceptionToAdd={0})", wayOfExceptionToAdd);
                throw;
            }
        }
        public async Task UpdateAsync(WayOfException wayOfExceptionToSave)
        {
            Stopwatch timespan = Stopwatch.StartNew();

            try
            {
                db.Entry(wayOfExceptionToSave).State = EntityState.Modified;
                await db.SaveChangesAsync();

                timespan.Stop();

                log.TraceApi("SQL Database", "WayOfExceptionRepository.UpdateAsync", timespan.Elapsed, "wayOfExceptionToSave={0}", wayOfExceptionToSave);
            }
            catch (Exception e)
            {
                log.Error(e, "Error in WayOfExceptionRepository.UpdateAsync(wayOfExceptionToSave={0})", wayOfExceptionToSave);
                throw;
            }
        }
Exemple #3
0
        public static ValidationResult ValidateWayOfException(WayOfException wayOfException, ValidationContext validationContext)
        {
            if (wayOfException == null)
            {
                return(null);
            }

            if (wayOfException.QuantityOpenPurchaseOrder < wayOfException.DeliveryAmount)
            {
                return(new ValidationResult("La Cantidad Total Orden de Compra (Kg) no puede ser menor a la Cantidad de Entregas."));
            }

            if ((wayOfException.QuantityOpenPurchaseOrder % wayOfException.DeliveryAmount) != 0)
            {
                return(new ValidationResult("La Cantidad Total Orden de Compra (Kg) / Cantidad de Entregas, debe resultar en un numero entero."));
            }

            return(null);
        }
        public async Task DeleteAsync(int wayOfExceptionID)
        {
            Stopwatch timespan = Stopwatch.StartNew();

            try
            {
                WayOfException wayOfException = await db.WayOfExceptions.FindAsync(wayOfExceptionID);

                db.WayOfExceptions.Remove(wayOfException);
                await db.SaveChangesAsync();

                timespan.Stop();
                log.TraceApi("SQL Database", "WayOfExceptionRepository.DeleteAsync", timespan.Elapsed, "wayOfExceptionID={0}", wayOfExceptionID);
            }
            catch (Exception e)
            {
                log.Error(e, "Error in WayOfExceptionRepository.DeleteAsync(wayOfExceptionID={0})", wayOfExceptionID);
                throw;
            }
        }