Пример #1
0
        public void MigrateOldDb(DateTime dtFrom, DateTime dtTo)
        {
            var categories = dbContext.Categories.AsNoTracking().ToList();

            dtFrom = dtFrom.Date;
            dtTo   = dtTo.Date + new TimeSpan(23, 59, 59);
            var oldBeginningAdjs = dbContext.Beginning_Adjustments.AsNoTracking().ToList();

            foreach (var oldBeginningAdj in oldBeginningAdjs)
            {
                var category = categories.FirstOrDefault(a => a.CategoryIdOld == oldBeginningAdj.CatId);

                var dt         = new DateTime(Convert.ToInt32(oldBeginningAdj.AdjYear), Convert.ToInt32(oldBeginningAdj.AdjMonth), 1);
                var weekDetail = new WeekDetail(dt);

                var newBegginingAdj = new BeginningInvAdj()
                {
                    BaleCount  = Convert.ToInt32(oldBeginningAdj.AdjustedBales),
                    CategoryId = category?.CategoryId ?? 0,
                    DMonth     = dt.Month,
                    DT         = dt,
                    DYear      = dt.Year,
                    FirstDay   = weekDetail.FirstDay,
                    LastDay    = weekDetail.LastDay,
                    WeekDay    = weekDetail.WeekDay,
                    WeekNum    = weekDetail.WeekNum,
                    Wt         = Convert.ToInt32(oldBeginningAdj.AdjustedVal),
                    Wt10       = Convert.ToInt32(oldBeginningAdj.Adjusted10)
                };

                dbContext.BeginningInvAdjs.Add(newBegginingAdj);
                dbContext.SaveChanges();
            }
            ;
        }
Пример #2
0
        public Dictionary <string, string> Validate(BeginningInvAdj model)
        {
            var modelErrors    = new Dictionary <string, string>();
            var duplicateCount = dbContext.BeginningInvAdjs.AsNoTracking().Count(a => a.CategoryId == model.CategoryId && a.DT == model.DT && a.BeginningInvAdjId != model.BeginningInvAdjId);

            if (duplicateCount > 0)
            {
                modelErrors.Add(nameof(model.CategoryId), "Entry already exists");
            }
            return(modelErrors);
        }
Пример #3
0
        private bool validateEntity(BeginningInvAdj model)
        {
            var modelErrors = repository.Validate(model);

            if (modelErrors.Count > 0)
            {
                foreach (var modelError in modelErrors)
                {
                    ModelState.AddModelError(modelError.Key, modelError.Value);
                }
            }
            return(ModelState.ErrorCount == 0);
        }
Пример #4
0
        public BeginningInvAdj Create(BeginningInvAdj model)
        {
            var weekDetail = new WeekDetail(model.DT);

            model.WeekDay  = weekDetail.WeekDay;
            model.WeekNum  = weekDetail.WeekNum;
            model.FirstDay = weekDetail.FirstDay;
            model.LastDay  = weekDetail.LastDay;


            dbContext.BeginningInvAdjs.Add(model);
            dbContext.SaveChanges();
            return(model);
        }
Пример #5
0
        public BeginningInvAdj Update(BeginningInvAdj model)
        {
            var entity = dbContext.BeginningInvAdjs.Find(model.BeginningInvAdjId);

            if (entity == null)
            {
                throw new Exception("Selected Record does not exists.");
            }

            entity.CategoryId = model.CategoryId;
            entity.Wt         = model.Wt;
            entity.Wt10       = model.Wt10;
            entity.BaleCount  = model.BaleCount;

            dbContext.BeginningInvAdjs.Update(entity);
            dbContext.SaveChanges();
            return(entity);
        }
Пример #6
0
        public IActionResult Put([FromBody] BeginningInvAdj model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(InvalidModelStateResult());
                }
                if (!validateEntity(model))
                {
                    return(InvalidModelStateResult());
                }

                return(Accepted(repository.Update(model)));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.GetExceptionMessages());
                return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.UpdateError));
            }
        }
Пример #7
0
 public bool Delete(BeginningInvAdj model)
 {
     dbContext.BeginningInvAdjs.Remove(model);
     dbContext.SaveChanges();
     return(true);
 }