Example #1
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_WarehouseCategoryModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                Spl_WarehouseCategory entity = await m_Rep.GetByIdAsync(model.Id);

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity            = new Spl_WarehouseCategory();
                entity.Id         = model.Id;
                entity.Code       = model.Code;
                entity.Category   = model.Category;
                entity.Name       = model.Name;
                entity.Sort       = model.Sort;
                entity.Remark     = model.Remark;
                entity.CreateTime = model.CreateTime;
                entity.Enable     = model.Enable;


                if (await m_Rep.CreateAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }
Example #2
0
        public virtual bool Edit(ref ValidationErrors errors, Spl_WarehouseCategoryModel model)
        {
            try
            {
                Spl_WarehouseCategory entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id         = model.Id;
                entity.Code       = model.Code;
                entity.Category   = model.Category;
                entity.Name       = model.Name;
                entity.Sort       = model.Sort;
                entity.Remark     = model.Remark;
                entity.CreateTime = model.CreateTime;
                entity.Enable     = model.Enable;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }