public HttpResponseMessage RegisterConsumer([FromBody] Consumer consumer)
        {
            try
            {
                Consumer existingConsumer = db.Consumers.Find(consumer.UserName);
                if (existingConsumer != null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Username Already Exists"));
                }

                Bank newConsumerBank = db.Banks.Find(consumer.IFSC);
                if (newConsumerBank == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid IFSC Code"));
                }

                Consumer newConsumer = new Consumer
                {
                    UserName        = consumer.UserName,
                    Name            = consumer.Name,
                    Email           = consumer.Email,
                    PhoneNumber     = consumer.PhoneNumber,
                    Password        = consumer.Password,
                    AccountNo       = consumer.AccountNo,
                    IFSC            = consumer.IFSC,
                    Address         = consumer.Address,
                    CardTypeNo      = consumer.CardTypeNo,
                    ApplicationDate = DateTime.Now,
                    DateOfBirth     = consumer.DateOfBirth,
                    IsPending       = true,
                    IsOpen          = false
                };

                Card companyCard = db.Cards.Find(consumer.CardTypeNo);
                if (companyCard == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid Card Scheme"));
                }

                CompanyCard newConsumerCard = new CompanyCard()
                {
                    CardNumber = $"{consumer.UserName}{consumer.IFSC}",
                    CardTypeNo = consumer.CardTypeNo,
                    UserName   = consumer.UserName,
                    Validity   = DateTime.Now.AddMonths(24),
                    Balance    = companyCard.CardLimit,
                    IsOpen     = false
                };

                db.Entry(newConsumer).State     = System.Data.Entity.EntityState.Added;
                db.Entry(newConsumerCard).State = System.Data.Entity.EntityState.Added;
                db.SaveChanges();

                return(Request.CreateResponse(HttpStatusCode.Created, "User Registered Successfully And Awaiting Verification"));
            } catch
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Consumer Could Not Be Registered"));
            }
        }
예제 #2
0
        public IHttpActionResult PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.CustomerID)
            {
                return(BadRequest());
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.ProductID)
            {
                return(BadRequest());
            }

            db.Entry(product).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #4
0
        public void Post([FromBody] Purchase pur)
        {
            FinanceEntities db = new FinanceEntities();
            PurchaseDetail  p  = new PurchaseDetail();

            p.ProductID = pur.id;
            p.CardID    = (from c in db.CardDetails
                           join u in db.Users
                           on c.CustomerID equals u.CustomerID
                           where u.Username == pur.username
                           select c.CardID).FirstOrDefault();
            p.PurchaseDate = DateTime.Now;
            p.CustomerID   = (from u in db.Users where u.Username == pur.username select u.CustomerID).FirstOrDefault();
            p.EmiScheme    = pur.scheme;
            p.EmiPerMonth  = pur.amount / pur.scheme;
            p.EmiPaid      = 0;
            p.EmiLeft      = pur.amount;
            p.PaidForMonth = "NO";
            db.PurchaseDetails.Add(p);
            db.SaveChanges();

            CardDetail query = (from c in db.CardDetails
                                where c.CustomerID == p.CustomerID
                                select c).FirstOrDefault();

            query.RemainingCredit = query.RemainingCredit - pur.amount;
            db.Entry(query).State = System.Data.Entity.EntityState.Modified;

            db.SaveChanges();
        }
예제 #5
0
        public void AddOrUpdateUser(UserProfile user)
        {
            try
            {
                using (var context = new FinanceEntities())
                {
                    if (user.UserId == 0)
                    {
                        context.UserProfile.Add(user);

                    }
                    else
                    {
                        var dbuser = context.UserProfile.Include(u => u.webpages_Roles).Single(u => u.UserId == user.UserId);
                        context.Entry(dbuser).CurrentValues.SetValues(user);
                        dbuser.webpages_Roles = new List<webpages_Roles>();
                        foreach (var role in user.webpages_Roles)
                        {
                            dbuser.webpages_Roles.Add(context.webpages_Roles.Single(r => r.RoleId == role.RoleId));
                        }
                    }

                    context.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                var message = e.Message;
                throw;
            }
            
        }
예제 #6
0
        public IHttpActionResult PutCardStatus(int id, [FromBody] CardDetail cardDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cardDetail.CustomerID)
            {
                return(BadRequest());
            }

            db.Entry(cardDetail).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CardDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #7
0
 public void UpdateCredit(Credit credit)
 {
     using (var context = new FinanceEntities())
     {
         context.Credit.Attach(credit);
         context.Entry(credit).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #8
0
 public void UpdateRequest(Request request)
 {
     using (var context = new FinanceEntities())
     {
         context.Request.Attach(request);
         context.Entry(request).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #9
0
 public void UpdateDeposit(Deposit deposit)
 {
     using (var context = new FinanceEntities())
     {
         context.Deposit.Attach(deposit);
         context.Entry(deposit).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #10
0
 public ActionResult Edit([Bind(Include = "UserId,FirstName,LastName,RegistrationDate")] tbUsers tbUsers)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbUsers).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tbUsers));
 }
예제 #11
0
 public ActionResult Edit([Bind(Include = "CurrencyId,Name")] tbCurrency tbCurrency)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbCurrency).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tbCurrency));
 }
예제 #12
0
 public ActionResult Edit([Bind(Include = "CreditId,UserId,MethodId,FullAmount,Amount,Date,Type,DateBegin,DateEnd,CurrencyId")] tbCredits tbCredits)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbCredits).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.tbUsers, "UserId", "FirstName", tbCredits.UserId);
     return(View(tbCredits));
 }
예제 #13
0
 public ActionResult Edit([Bind(Include = "MethodId,UserId,Name,Type,IsClosed")] tbMethod tbMethod)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbMethod).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.tbUsers, "UserId", "FirstName", tbMethod.UserId);
     return(View(tbMethod));
 }
예제 #14
0
 public ActionResult Edit([Bind(Include = "SpendingId,UserId,MethodId,Amount,Date,CurrencyId")] tbSpending tbSpending)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbSpending).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.tbUsers, "UserId", "FirstName", tbSpending.UserId);
     return(View(tbSpending));
 }
예제 #15
0
        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="account">新用户</param>
        /// <returns>影响行数</returns>
        public int newUser(Account account)
        {
            int result = 0;

            try
            {
                fin.Entry <Account>(account).State = EntityState.Added;
                result = fin.SaveChanges();
            }
            catch (Exception ex)
            {
                FinanceToError.getFinanceToError().toError();
            }
            return(result);
        }
예제 #16
0
        public void SaveUpdateCreditType(CreditType model)
        {
            using (var context = new FinanceEntities())
            {
                if (model.Id == 0)
                {
                    context.CreditType.Add(model);
                }
                else
                {
                    context.Entry(model).State = EntityState.Modified;;
                }

                context.SaveChanges();
            }
        }
예제 #17
0
        public HttpResponseMessage DeductEmi()
        {
            try
            {
                var currentDate = DateTime.Now;

                foreach (var tran in financeEntities.Transactions)
                {
                    CompanyCard tranCard = financeEntities.CompanyCards.Where(c => c.UserName == tran.UserName).FirstOrDefault();
                    if (tranCard == null)
                    {
                        continue;
                    }

                    var  dayDifference = (currentDate - tran.LastChecked).Days;
                    bool isEmiDate     = (currentDate - tran.PurchaseDate).Days % 30 == 0;

                    if (tranCard.IsOpen && dayDifference > 0 && isEmiDate && tran.RemainingAmount > 0)
                    {
                        var currentRemainingAmount = tran.RemainingAmount - tran.EMIAmount;
                        tran.RemainingAmount = currentRemainingAmount;

                        var currentBalance = tranCard.Balance - tran.EMIAmount;
                        tranCard.Balance = currentBalance;

                        Deduction newDeduction = new Deduction()
                        {
                            UserName      = tran.UserName,
                            ProductID     = tran.ProductID,
                            DeductionDate = DateTime.Now,
                            EMIAmout      = tran.EMIAmount
                        };
                        financeEntities.Entry(newDeduction).State = System.Data.Entity.EntityState.Added;
                    }
                    tran.LastChecked = DateTime.Now;
                }

                financeEntities.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK, "Operation Completed Successfully"));
            } catch
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Something Went Wrong"));
            }
        }
예제 #18
0
        public HttpResponseMessage PlaceOrder([FromBody] Order newOrder)
        {
            try
            {
                Consumer consumer = financeEntities.Consumers.Find(newOrder.UserName);
                if (consumer == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Username Is Invalid"));
                }

                Product selectedProduct = financeEntities.Products.Find(newOrder.ProductID);
                if (selectedProduct == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Product Could Not Be Found"));
                }

                EMI scheme = financeEntities.EMIs.Find(newOrder.SchemeNo);
                if (scheme == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "EMI Scheme Could Not Be Found"));
                }

                CompanyCard companyCard = financeEntities.CompanyCards.Where(c => c.UserName == newOrder.UserName).FirstOrDefault();
                if (companyCard == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Conumser Card Balance Could Not Be Fetched"));
                }

                int emiCost     = CalculateMonthlyEMI(selectedProduct, scheme.Months);
                int orderAmount = emiCost * scheme.Months;

                if (orderAmount > companyCard.Balance)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Insufficient Balance To Place Order"));
                }

                if (DateTime.Compare(companyCard.Validity, DateTime.Now) < 0)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Your Card Is Deactivated"));
                }

                Transaction newTransaction = new Transaction()
                {
                    UserName        = consumer.UserName,
                    ProductID       = selectedProduct.ProductID,
                    SchemeNo        = scheme.SchemeNo,
                    PurchaseDate    = DateTime.Now,
                    EMIAmount       = emiCost,
                    RemainingAmount = orderAmount - emiCost,
                    LastChecked     = DateTime.Now
                };
                financeEntities.Entry(newTransaction).State = System.Data.Entity.EntityState.Added;

                var currentBalance = companyCard.Balance - emiCost;
                companyCard.Balance = currentBalance;

                Deduction newAmountDeduction = new Deduction()
                {
                    UserName      = consumer.UserName,
                    DeductionDate = DateTime.Now,
                    EMIAmout      = emiCost,
                    ProductID     = selectedProduct.ProductID
                };
                financeEntities.Entry(newAmountDeduction).State = System.Data.Entity.EntityState.Added;

                financeEntities.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.Created, "Order Placed Successfully"));
            } catch
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Order Could Not Be Placed"));
            }
        }