Пример #1
0
        public GLLines GetSingle(string id, long companyId)
        {
            GLLines entity = this.GetAll(companyId)
                             .FirstOrDefault(x => x.Id == Convert.ToInt64(id));

            return(entity);
        }
Пример #2
0
        private static GLLines getEntityByModel(GLLinesModel model, decimal conversionRate)
        {
            if (model == null)
            {
                return(null);
            }

            GLLines entity = new GLLines();

            entity.Id                = model.Id;
            entity.HeaderId          = model.HeaderId;
            entity.CodeCombinationId = model.CodeCombinationId;
            entity.Description       = model.Description;
            entity.EnteredCr         = model.EnteredCr;
            entity.EnteredDr         = model.EnteredDr;
            entity.AccountedCr       = model.EnteredCr * conversionRate;
            entity.AccountedDr       = model.EnteredDr * conversionRate;
            entity.Qty               = model.Quantity;
            entity.TaxRateCode       = model.TaxRateCode;
            if (model.Id == 0)
            {
                entity.CreateBy   = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
            }
            else
            {
                entity.CreateBy   = model.CreateBy;
                entity.CreateDate = model.CreateDate;
            }
            entity.UpdateBy   = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;
            return(entity);
        }
Пример #3
0
        public string Update(GLLines entity)
        {
            var originalEntity = this.Context.GLLines.Find(entity.Id);

            this.Context.Entry(originalEntity).CurrentValues.SetValues(entity);
            this.Context.Entry(originalEntity).State = EntityState.Modified;
            this.Commit();
            return(entity.Id.ToString());
        }
Пример #4
0
        public static void Update(GLHeaderModel jv)
        {
            GLHeader entity = getEntityByModel(jv);

            string result = string.Empty;

            if (entity.IsValid())
            {
                if (jv.Id > 0)
                {
                    result = service.Update(entity);
                }
                else
                {
                    result = service.Insert(entity);
                }

                if (!string.IsNullOrEmpty(result))
                {
                    var savedLines = getGLLinesByHeaderId(result);
                    if (savedLines.Count() > jv.GlLines.Count())
                    {
                        var tobeDeleted = savedLines.Take(savedLines.Count() - jv.GlLines.Count());
                        foreach (var item in tobeDeleted)
                        {
                            lineService.Delete(item.Id.ToString(), AuthenticationHelper.CompanyId.Value);
                        }
                        savedLines = getGLLinesByHeaderId(result);
                    }

                    foreach (var line in jv.GlLines)
                    {
                        GLLines lineEntity = getEntityByModel(line, jv.ConversionRate);
                        if (lineEntity.IsValid())
                        {
                            lineEntity.HeaderId = Convert.ToInt64(result);
                            if (savedLines.Count() > 0)
                            {
                                lineEntity.Id = savedLines.FirstOrDefault().Id;
                                savedLines.Remove(savedLines.FirstOrDefault(rec => rec.Id == lineEntity.Id));
                                lineService.Update(lineEntity);
                            }
                            else
                            {
                                lineService.Insert(lineEntity);
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
 public GLLinesModel(GLLines entity)
 {
     this.Id                = entity.Id;
     this.HeaderId          = entity.HeaderId;
     this.CodeCombinationId = entity.CodeCombinationId;
     this.EnteredCr         = entity.EnteredCr;
     this.EnteredDr         = entity.EnteredDr;
     this.AccountedCr       = entity.AccountedCr;
     this.AccountedDr       = entity.AccountedDr;
     this.Quantity          = entity.Qty;
     this.Description       = entity.Description;
     this.TaxRateCode       = entity.TaxRateCode;
     this.CreateBy          = entity.CreateBy;
     this.CreateDate        = entity.CreateDate;
     this.UpdateBy          = entity.UpdateBy;
     this.UpdateDate        = entity.UpdateDate;
 }
Пример #6
0
 public string Update(GLLines entity)
 {
     return(this.repository.Update(entity));
 }
Пример #7
0
 public string Insert(GLLines entity)
 {
     return(this.repository.Insert(entity));
 }
Пример #8
0
 public string Insert(GLLines entity)
 {
     this.Context.GLLines.Add(entity);
     this.Commit();
     return(entity.Id.ToString());
 }