Ejemplo n.º 1
0
        public async Task <LuongPhuCap> Update(LuongPhuCap model)
        {
            return(await WithConnection(async c =>
            {
                var obj = await c.GetAsync(model);

                if (obj == null)
                {
                    throw new Exception(string.Format("Update id {0} not exist", model.LuongPhuCapId.ToString()));
                }

                if (obj.CtrVersion != model.CtrVersion)
                {
                    throw new Exception(string.Format("Update id {0} have version confict"
                                                      , model.LuongPhuCapId.ToString()));
                }

                model.CtrVersion += 1;

                var result = await c.UpdateAsync(model);

                if (result != true)
                {
                    throw new Exception("Update Fail");
                }

                return model;
            }));
        }
Ejemplo n.º 2
0
        public async Task <LuongPhuCap> Insert(LuongPhuCap obj)
        {
            return(await WithConnection(async c =>
            {
                await c.InsertAsync(obj);

                if (obj.LuongPhuCapId == 0)
                {
                    throw new Exception("Insert Fail");
                }

                return obj;
            }));
        }
Ejemplo n.º 3
0
        public async Task <LuongPhuCap> UpdatePartialBase(LuongPhuCap model, bool checkCtrVersion, params string[] field)
        {
            return(await WithConnection(async c =>
            {
                var obj = await c.GetAsync(model);

                if (obj == null)
                {
                    throw new Exception(string.Format("Update id {0} not exist", model.LuongPhuCapId.ToString()));
                }

                if (checkCtrVersion == true && obj.CtrVersion != model.CtrVersion)
                {
                    throw new Exception(string.Format("Update id {0} have version confict"
                                                      , model.LuongPhuCapId.ToString()));
                }

                model.CtrVersion += 1;
                var list = field.ToList();

                list.Add(nameof(LuongPhuCap.CtrVersion));

                var partialUpdateMapping = OrmConfiguration
                                           .GetDefaultEntityMapping <LuongPhuCap>()
                                           .Clone() // clone it if you don't want to modify the default
                                           .UpdatePropertiesExcluding(prop => prop.IsExcludedFromUpdates = true,
                                                                      list.ToArray());

                var result = await c.UpdateAsync(model, statement => statement.WithEntityMappingOverride(partialUpdateMapping));

                if (result != true)
                {
                    throw new Exception("Update Fail");
                }

                return model;
            }));
        }
Ejemplo n.º 4
0
 public async Task <LuongPhuCap> UpdatePartial(LuongPhuCap model, params string[] field)
 {
     return(await UpdatePartialBase(model, true, field));
 }