Пример #1
0
        public async Task <User> Save(User user)
        {
            try
            {
                var data = _context.Users.AsNoTracking().Where(p => p.Username == user.Username).FirstOrDefault();
                if (data == null)
                {
                    user.AddedDate   = DateTime.Now;
                    user.UpdatedDate = DateTime.Now;
                    var rs = _context.Users.Add(user);
                    user = rs.Entity;
                }
                else
                {
                    user.UpdatedDate = DateTime.Now;
                    var rs = _context.Users.Update(user);
                    user = rs.Entity;
                }
                await _context.SaveChangesAsync();

                return(user);
            }catch (Exception ex)
            {
                return(null);
            }
        }
Пример #2
0
        public async Task <Customer> Save(Customer customer)
        {
            try
            {
                var data = _context.Customers.AsNoTracking().Where(p => p.Id == customer.Id).FirstOrDefault();
                if (data == null)
                {
                    customer.AddedDate   = DateTime.Now;
                    customer.UpdatedDate = DateTime.Now;
                    var rs = _context.Customers.Add(customer);
                    customer = rs.Entity;
                }
                else
                {
                    customer.UpdatedDate = DateTime.Now;
                    var rs = _context.Customers.Update(customer);
                    customer = rs.Entity;
                }
                await _context.SaveChangesAsync();

                return(customer);
            }catch (Exception ex)
            {
                return(null);
            }
        }
Пример #3
0
        public async Task <Product> Save(Product product)
        {
            try
            {
                var data = _context.Products.AsNoTracking().Where(p => p.Id == product.Id).FirstOrDefault();
                if (data == null)
                {
                    product.AddedDate   = DateTime.Now;
                    product.UpdatedDate = DateTime.Now;
                    var rs = _context.Products.Add(product);
                    product = rs.Entity;
                }
                else
                {
                    product.UpdatedDate = DateTime.Now;
                    var rs = _context.Products.Update(product);
                    product = rs.Entity;
                }
                await _context.SaveChangesAsync();

                return(product);
            }catch (Exception ex)
            {
                return(null);
            }
        }
Пример #4
0
        public async Task <DrawPieImage> Save(DrawPieImage drawPie)
        {
            try
            {
                var slot = drawPie.Slot;
                drawPie.Slot = null;
                var data = _context.DrawPieImages.AsNoTracking().Where(p => p.Id == drawPie.Id).FirstOrDefault();
                if (data == null)
                {
                    drawPie.AddedDate   = DateTime.Now;
                    drawPie.UpdatedDate = DateTime.Now;
                    var rs = _context.DrawPieImages.Add(drawPie);
                    drawPie = rs.Entity;
                }
                else
                {
                    drawPie.UpdatedDate = DateTime.Now;
                    var rs = _context.DrawPieImages.Update(drawPie);
                    drawPie = rs.Entity;
                }

                await _context.SaveChangesAsync();

                drawPie.Slot = slot;
                return(drawPie);
            }catch (Exception ex)
            {
                return(null);
            }
        }
Пример #5
0
        public async Task <Slot> Save(Slot slot)
        {
            try
            {
                var data = _context.Slots.AsNoTracking().Where(p => p.Id == slot.Id).FirstOrDefault();
                if (data == null)
                {
                    slot.AddedDate   = DateTime.Now;
                    slot.UpdatedDate = DateTime.Now;
                    var rs = _context.Slots.Add(slot);
                    slot = rs.Entity;
                }
                else
                {
                    slot.UpdatedDate = DateTime.Now;
                    var rs = _context.Slots.Update(slot);
                    slot = rs.Entity;
                }
                await _context.SaveChangesAsync();

                return(slot);
            }catch (Exception ex)
            {
                return(null);
            }
        }