Example #1
0
 public IActionResult Create(Employee emp)
 {
     if (!ModelState.IsValid)
     {
         return(View(emp));
     }
     _context.Add(emp);
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }
Example #2
0
    public Group AddGroup(GroupModel model)
    {
        var group = context.Groups.Add(model.Group);

        context.SaveChanges();
        foreach (var item in model.MembersId)
        {
            GroupMembers groupMembers = new GroupMembers()
            {
                GroupId = model.Group.GroupId,
                UserId  = item,
            };

            context.GroupMembers.Add(groupMembers);
            context.SaveChanges();
        }
        var activity = new Activity();

        activity.Activitydata = "You Added" + model.Group.Title + "Group";
        activity.Date         = DateTime.Now.ToString();
        activity.UserId       = model.Group.CreatorIdId;

        context.Activities.Add(activity);
        context.SaveChanges();

        return(model.Group);
    }
Example #3
0
 public ActionResult Register(Register Registration)
 {
     db.Registration.Add(Registration);
     db.SaveChanges();
     db1.Registration.Add(Registration);
     db1.SaveChanges();
     return(View());
 }
Example #4
0
    public async Task <Applicationuser> Deletefriend(string userid, string friendid)
    {
        var activity = new Activity();
        var friend   = context.Friends.ToList().FirstOrDefault(x => x.UserId == userid && x.FrndId == friendid);

        if (friend != null)
        {
            var user = await UserManager.FindByIdAsync(friend.FrndId);

            context.Friends.Remove(friend);
            context.SaveChanges();
            activity.Activitydata = "You removed" + user.UserName + "From your friend list";
            activity.Date         = DateTime.Now.ToString();
            activity.UserId       = friend.UserId;



            context.Activities.Add(activity);
            context.SaveChanges();
            return(user);
        }



        return(null);
    }
Example #5
0
    public Transaction Add(TransactionModel transactionn)
    {
        var transaction = new Transaction()
        {
            PaidAmount = transactionn.PaidAmount,
            PayeeId    = transactionn.PayeeId,
            PayerId    = transactionn.PayerId,
        };

        var trans = UpdateSettelement(transaction);

        context.Payments.Add(transaction);
        context.SaveChanges();

        return(trans);
    }
Example #6
0
    public Expense AddExpense(ExpenseModel expenseModel)
    {
        this.context.Expenses.Add(expenseModel.Expense);
        context.SaveChanges();

        if (expenseModel.Expense
            .GroupId != null)
        {
            GroupExpense groupExpense = new GroupExpense()
            {
                ExpenseId = expenseModel.Expense.ExpenseId,
                GroupId   = expenseModel.Expense.GroupId,
            };
            context.GroupsofExpenses.Add(groupExpense);
            context.SaveChanges();
        }


        foreach (var item in expenseModel.Shares)
        {
            item.ExpenseId = expenseModel.Expense.ExpenseId;
            context.Shareinfo.Add(item);
            context.SaveChanges();
        }
        foreach (var item in expenseModel.Payers)
        {
            var share = GetShare(item.PayerId, expenseModel.Expense.ExpenseId);

            Expenseinfo expenseinfo = new Expenseinfo();
            expenseinfo.ExpenseId   = expenseModel.Expense.ExpenseId;
            expenseinfo.PaidAmouunt = item.Amount;
            expenseinfo.UserId      = item.PayerId;
            expenseinfo.ShareId     = share.ShareId;
            expenseinfo.shareamount = share.ShareAmount;
            if ((share.ShareAmount - item.Amount) >= 0)
            {
                expenseinfo.BorrowedAmout = share.ShareAmount - item.Amount;
                expenseinfo.LentedAmout   = 0;
            }
            else
            {
                expenseinfo.LentedAmout = item.Amount - share.ShareAmount;
            }

            context.Expensesinfo.Add(expenseinfo);
            context.SaveChanges();
        }

        var expenseinfolist = context.Expensesinfo.ToList().Where(x => x.ExpenseId == expenseModel.Expense.ExpenseId);

        foreach (var item in expenseinfolist)
        {
            var LentedAmout = item.LentedAmout;
            if (LentedAmout > 0)
            {
                foreach (var subitem in expenseinfolist)
                {
                    var BorrowedAmout = subitem.BorrowedAmout;

                    if (LentedAmout < 0)
                    {
                        break;
                    }
                    if (item.UserId == subitem.UserId)
                    {
                        continue;
                    }

                    if (BorrowedAmout > 0)
                    {
                        Settelement settelement = new Settelement();
                        settelement.ExpenseId  = expenseModel.Expense.ExpenseId;
                        settelement.BorrowerId = subitem.UserId;
                        settelement.LenterId   = item.UserId;
                        settelement.GroupId    = expenseModel.Expense.GroupId;
                        if (LentedAmout >= BorrowedAmout)
                        {
                            settelement.SettelementAmount = BorrowedAmout;
                            LentedAmout   = LentedAmout - BorrowedAmout;
                            BorrowedAmout = 0;
                        }
                        if (LentedAmout < BorrowedAmout)
                        {
                            settelement.SettelementAmount = LentedAmout;
                            LentedAmout   = 0;
                            BorrowedAmout = BorrowedAmout - LentedAmout;
                        }

                        context.Settelements.Add(settelement);
                        context.SaveChanges();
                    }
                }
            }
        }

        var activity = new Activity()
        {
            Activitydata = "You" + expenseModel.Expense.Title + "Added",
            Date         = DateTime.Now.ToString(),
            UserId       = expenseModel.Expense.UserId,
        };

        context.Activities.Add(activity);
        context.SaveChanges();



        return(expenseModel.Expense);
    }
 public void Create(Employee emp)
 {
     _context.Employees.Add(emp);
     _context.SaveChanges();
 }