Esempio n. 1
0
        public async Task <Metadata> Delete(long RoleID)
        {
            Metadata res = new Metadata();

            try
            {
                var dataRoles = await context.Roles.FirstOrDefaultAsync(x => x.roleid == RoleID);

                if (dataRoles == null)
                {
                    return new Metadata()
                           {
                               status = false, data = "Data not found"
                           }
                }
                ;

                context.RoleScreen.RemoveRange(context.RoleScreen.Where(x => x.roleid == RoleID));
                context.Remove(dataRoles);
                await context.SaveChangesAsync();

                res.status = true;
                res.data   = "Data was successfully deleted";
            }
            catch (Exception ex)
            {
                res.status = false;
                res.data   = ex.Message;
            }
            return(res);
        }
Esempio n. 2
0
        public async Task <Metadata> Delete(long ResidentID)
        {
            Metadata res = new Metadata();

            try
            {
                var resident = (from r in context.Resident where r.residentid == ResidentID select r).FirstOrDefault();

                if (resident == null)
                {
                    return(new Metadata()
                    {
                        data = "Resident not found", status = false
                    });
                }

                context.Resident.Remove(resident);

                await context.SaveChangesAsync();

                res.status = true;
                res.data   = "Data Deleted";
            }
            catch (Exception e)
            {
                res.data = e.Message.ToString();
            }
            return(res);
        }
Esempio n. 3
0
        public async Task <Metadata> Delete(long CustomerID)
        {
            Metadata res = new Metadata();

            try
            {
                var Customer = (from r in context.Customer where r.customerid == CustomerID select r).FirstOrDefault();

                if (Customer == null)
                {
                    return(new Metadata()
                    {
                        data = "Customer not found", status = false
                    });
                }

                context.Customer.Remove(Customer);

                await context.SaveChangesAsync();

                res.status = true; res.data = "Data Deleted";
            }
            catch (Exception e)
            {
                res.data = e.Message.ToString();
            }
            return(res);
        }
Esempio n. 4
0
        public async Task <Metadata> Insert(UserViewModel model)
        {
            Metadata res = new Metadata();

            try
            {
                var dataUSer = await context.Users.AnyAsync(x => x.username.ToLower().Replace(" ", "") == model.UserName.ToLower().Replace(" ", "") && x.userid != model.UserID);

                if (dataUSer)
                {
                    return new Metadata()
                           {
                               status = false, data = "User name is ready"
                           }
                }
                ;
                string saltNow = GenerateSalt();
                await context.Users.AddAsync(new UserModel()
                {
                    email    = model.Email,
                    username = model.UserName,
                    salt     = saltNow,
                    password = HashedPassword(model.Password, saltNow),
                    roleid   = model.RoleID
                });

                await context.SaveChangesAsync();

                res.status = true;
                res.data   = "Data was successfully inserted";
            }
            catch (Exception ex)
            {
                res.status = false;
                res.data   = ex.Message;
            }

            return(res);
        }
Esempio n. 5
0
        public async Task <Metadata> update(RoleScreenViewModel model)
        {
            Metadata res = new Metadata();

            if (model.RoleID == 0 || model.Screens == null || model.Screens.Count == 0)
            {
                return(new Metadata()
                {
                    data = "Application not allowed"
                });
            }
            ;
            try
            {
                _context.RoleScreen.RemoveRange(_context.RoleScreen.Where(x => x.roleid == model.RoleID));
                List <RoleScreenModel> lsModel = new List <RoleScreenModel>();
                model.Screens.ForEach(rolescreen =>
                {
                    lsModel.Add(new RoleScreenModel()
                    {
                        roleid     = model.RoleID,
                        screenid   = rolescreen.ScreenID,
                        deleteflag = rolescreen.DeleteFlag,
                        readflag   = rolescreen.ReadFlag,
                        writeflag  = rolescreen.WriteFlag
                    });
                });
                _context.RoleScreen.AddRange(lsModel);
                int affect = await _context.SaveChangesAsync();

                res.status = true;
            }
            catch (Exception e)
            {
                res.data = e.Message.ToString();
            }
            return(res);
        }
Esempio n. 6
0
        public async Task <Metadata> SaveTransactionAsync(TransactionViewModel model)
        {
            Metadata res = new Metadata();
            await context.Database.BeginTransactionAsync();

            try
            {
                var txn = await context.Trx.Where(x => x.trxdate.Date == model.TrxDate.Date).FirstOrDefaultAsync();

                if (txn == null)
                {
                    txn             = new TransactionModel();
                    txn.createdby   = model.CreatedBy;
                    txn.createddate = model.CreatedDate;
                    txn.total       = 0;
                    txn.trxdate     = model.TrxDate.Date;
                    await context.Trx.AddAsync(txn);
                }
                else
                {
                    txn.updatedby   = model.CreatedBy;
                    txn.updateddate = model.CreatedDate;
                    txn.total       = 0;
                    context.Trx.Update(txn);
                }
                await context.SaveChangesAsync();

                var itemTxn = context.TrxItem.Where(x => x.trxid == txn.trxid);
                foreach (var item in model.listItemTrx)
                {
                    if (item.TrxItemID != null && itemTxn.Any(x => x.trxitemid == item.TrxItemID))
                    {
                        var itemTxnDetail = itemTxn.Where(x => x.trxitemid == item.TrxItemID).FirstOrDefault();
                        itemTxnDetail.afteramount  = (decimal)item.AfterAmount;
                        itemTxnDetail.beforeamount = (decimal)item.BeforeAmount;
                        itemTxnDetail.qty          = (decimal)item.Qty;
                        context.TrxItem.Update(itemTxnDetail);
                    }
                    else
                    {
                        var modelTxnItem = new TrxItemModel()
                        {
                            afteramount  = (decimal)item.AfterAmount,
                            beforeamount = (decimal)item.BeforeAmount,
                            qty          = (decimal)item.Qty,
                            price        = (decimal)item.Price,
                            trxid        = txn.trxid,
                            customerid   = (long)item.CustomerID,
                            isclear      = false,
                            residentid   = (long)item.ResidentID
                        };
                        await context.TrxItem.AddAsync(modelTxnItem);
                    }
                }
                await context.SaveChangesAsync();

                await context.Database.CommitTransactionAsync();

                res.status = true;
            }
            catch (Exception ex)
            {
                await context.Database.RollbackTransactionAsync();

                res.data = ex.Message;
            }
            return(res);
        }