Example #1
0
 public int AddRent(ModelRents model)
 {
     try
     {
         using (var db = new DAL.BikeEntities())
         {
             db.Rents.Add(MapToDB(model));
             db.SaveChanges();
             return(MapToApp(db.Set <DAL.Rents>().OrderByDescending(t => t.id).FirstOrDefault()).id);
         }
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
Example #2
0
        public ActionResult Confirm(ModelRents model)
        {
            if (listbodyrents.Count > 0)
            {
                if (ModelState.IsValid)
                {
                    model.date     = DateTime.Now;
                    model.quantity = listbodyrents.Count;
                    double price = 0;
                    foreach (var item in listbodyrents)
                    {
                        price += item.price;
                    }


                    if (model.typepromotions_id != 0)
                    {
                        var     promotion = _repositorytypepromotions.SelectTypePromotionById(model.typepromotions_id);
                        decimal disc      = Convert.ToDecimal(price) * (Convert.ToDecimal(promotion.discount) / 100);
                        model.price = price - Convert.ToDouble(disc);
                    }
                    else
                    {
                        model.price = price;
                    }


                    int result = _repositoryrents.AddRent(model);

                    foreach (var item in listbodyrents)
                    {
                        item.rents_id = result;
                        item.date     = model.date;
                        _repositorybodyrents.AddBodyRent(item);
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Confirm"));
                }
            }
            else
            {
                return(RedirectToAction("Create"));
            }
        }
Example #3
0
 private DAL.Rents MapToDB(ModelRents model)
 {
     try
     {
         return(new DAL.Rents()
         {
             id = model.id,
             price = model.price,
             typepromotions_id = model.typepromotions_id,
             clients_id = model.clients_id,
             date = model.date,
             quantity = model.quantity
         });
     }
     catch (Exception ex)
     {
         return(null);
     }
 }