public IHttpActionResult PostMonthlyBill(MonthlyBill monthlyBill)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.MonthlyBills.Add(monthlyBill);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (MonthlyBillExists(monthlyBill.BILL))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = monthlyBill.BILL }, monthlyBill));
        }
        public IHttpActionResult PutMonthlyBill(string id, MonthlyBill monthlyBill)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != monthlyBill.BILL)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public IHttpActionResult MonthlyBill(MonthlyBill monthlyBill)
        {
            if (monthlyBill == null)
            {
                return(BadRequest("null values"));
            }


            var billInDb = _context.MonthlyBills.SingleOrDefault(m => m.Id == 1);

            if (billInDb == null)
            {
                _context.MonthlyBills.Add(monthlyBill);
            }
            else
            {
                billInDb.RoomBill     = monthlyBill.RoomBill;
                billInDb.ServicePrice = monthlyBill.ServicePrice;
            }


            _context.SaveChanges();

            return(Ok(monthlyBill));
        }
        public bool UpdateMonthly(MonthlyBill monthlyBill)
        {
            string ASPUser = GetUserId();
            var    mgr     = new GetBills();

            mgr.UpdateMonthly(monthlyBill);
            return(true);
        }
Ejemplo n.º 5
0
 public System.Web.Mvc.JsonResult InsertMonthlyBills(MonthlyBill monthlyBill)
 {
     using (BillsEntities entities = new BillsEntities())
     {
         entities.MonthlyBills.Add(monthlyBill);
         entities.SaveChanges();
     }
     return(Json(monthlyBill));
 }
        public IHttpActionResult GetMonthlyBill(string id)
        {
            MonthlyBill monthlyBill = db.MonthlyBills.Find(id);

            if (monthlyBill == null)
            {
                return(NotFound());
            }
            return(Ok(monthlyBill));
        }
        public PartialViewResult InsertMonthly(MonthlyBill monthlyBillInsert)
        {
            string ASPUser = GetUserId();
            var    mgr     = new GetBills();

            mgr.InsertMonthly(monthlyBillInsert, ASPUser);
            var model = new BillsViewModel();

            model.MonthlyBills = mgr.getMonthlyBills(ASPUser);
            return(PartialView("_PartialMonthly", model));
        }
Ejemplo n.º 8
0
        private static MonthlyBill CreateMonthlyBill(BillJson billJson)
        {
            var bill = new MonthlyBill();

            bill.Amount        = billJson.Amount;
            bill.CategoryID    = billJson.CategoryId;
            bill.SubCategoryID = billJson.SubCategoryId;
            bill.Description   = billJson.Description;
            bill.PayerID       = billJson.PayerId;

            return(bill);
        }
Ejemplo n.º 9
0
        public void BillCurrentMonth()
        {
            var    monthlyPlan = MockData.MonthlyPayment;
            var    monthlyPlanRemainingAmount = 0.0;
            var    callsForProcessing         = MockData.CallsMade;
            double totalPrice              = 0.0;
            double localCallsTotalPrice    = 0.0;
            double externalCallsTotalPrice = 0.0;

            CallHelper helperInstance = new CallHelper();

            helperInstance.ProcessCalls(ref callsForProcessing);

            MonthlyBill bill = new MonthlyBill(callsForProcessing, monthlyPlan);

            var processedCalls = callsForProcessing.OrderBy(c => c.TimeCalled).ToList();

            //Debug order
            //var processedCalls = callsForProcessing;

            totalPrice                 = processedCalls.Sum(s => s.Cost);
            localCallsTotalPrice       = processedCalls.Where(c => c.CallType == CallType.Local || c.CallType == CallType.LocalPrime).Sum(c => c.Cost);
            externalCallsTotalPrice    = processedCalls.Where(c => c.CallType == CallType.National || c.CallType == CallType.International).Sum(c => c.Cost);
            monthlyPlanRemainingAmount = monthlyPlan.Amount - totalPrice;

            Console.WriteLine("Abono mensual: $" + monthlyPlan.Amount);
            Console.WriteLine("Detalle de consumos del mes (por fecha):");
            Console.WriteLine("Tipo de llamada | Destino | Costo por Minuto | Horario de llamado | Duración (en minutos) | Costo total por llamada");
            //Print recipe
            foreach (var call in processedCalls)
            {
                Console.Write(call.CallType.ToString() + " | ");
                Console.Write(call.Destination.Name + " | ");
                Console.Write("$" + call.Destination.Cost.ToString() + " | ");
                Console.Write(call.TimeCalled.DayOfWeek + ", " + call.TimeCalled.ToString() + " | ");
                Console.Write(call.DurationInMinutes.ToString() + " | ");
                Console.Write("$" + call.Cost.ToString());

                Console.WriteLine();
            }

            Console.WriteLine("Consumo en llamadas Locales: $" + localCallsTotalPrice);

            Console.WriteLine("Consumo en llamadas Nacionales/Internacionales: $" + externalCallsTotalPrice);

            Console.WriteLine("Costo total en consumo mensual: $" + totalPrice);

            Console.WriteLine("Crédito restante en el plan mensual: $" + monthlyPlanRemainingAmount);

            Console.WriteLine("Presione cualquier tecla para salir...");
            Console.ReadKey();
        }
Ejemplo n.º 10
0
        public ActionResult Delete(int id)
        {
            using (BillsEntities entities = new BillsEntities())
            {
                MonthlyBill mb = (from c in entities.MonthlyBills
                                  where c.id == id
                                  select c).FirstOrDefault();
                entities.MonthlyBills.Remove(mb);
                entities.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 11
0
        public ActionResult UpdateMonthlyPaid(MonthlyBill monthlyPaid)
        {
            using (BillsEntities entities = new BillsEntities())
            {
                MonthlyBill updatedPaid = (from c in entities.MonthlyBills
                                           where c.id == monthlyPaid.id
                                           select c).FirstOrDefault();
                updatedPaid.Paid_ = monthlyPaid.Paid_;

                entities.SaveChanges();
            }
            //return View(monthlyBill);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 12
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MonthlyBill monthlyBill = db.MonthlyBills.Find(id);

            if (monthlyBill == null)
            {
                return(HttpNotFound());
            }
            return(View(monthlyBill));
        }
        public IHttpActionResult DeleteMonthlyBill(string id)
        {
            MonthlyBill monthlyBill = db.MonthlyBills.Find(id);

            if (monthlyBill == null)
            {
                return(NotFound());
            }

            db.MonthlyBills.Remove(monthlyBill);
            db.SaveChanges();

            return(Ok(monthlyBill));
        }
Ejemplo n.º 14
0
        private static Bill CreateBill(MonthlyBill monthlyBill, DateTime dueDate)
        {
            var bill = new Bill();

            bill.Amount        = monthlyBill.Amount;
            bill.CategoryID    = monthlyBill.CategoryID;
            bill.SubCategoryID = monthlyBill.SubCategoryID;
            bill.Description   = monthlyBill.Description;
            bill.PayerID       = monthlyBill.PayerID;
            bill.DueDate       = dueDate;
            bill.RegDate       = DateTime.Now;

            return(bill);
        }
Ejemplo n.º 15
0
 public ActionResult UpdateMonthlyBills(MonthlyBill monthlyBill)
 {
     using (BillsEntities entities = new BillsEntities())
     {
         MonthlyBill updatedBills = (from c in entities.MonthlyBills
                                     where c.id == monthlyBill.id
                                     select c).FirstOrDefault();
         updatedBills.Bill  = monthlyBill.Bill;
         updatedBills.Date  = monthlyBill.Date;
         updatedBills.Cost  = monthlyBill.Cost;
         updatedBills.Paid_ = monthlyBill.Paid_;
         entities.SaveChanges();
     }
     //return View(monthlyBill);
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 16
0
 public static bool AddMonthlyBill(MonthlyBill bill)
 {
     using (var ctx = new EconomyContext())
     {
         try
         {
             ctx.MonthlyBills.Add(bill);
             ctx.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             return(false);
         }
     }
 }
Ejemplo n.º 17
0
        public bool UpdateMonthly(MonthlyBill monthlyBill)
        {
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("id", monthlyBill.id);
            parameters.Add("Bill", monthlyBill.Bill);
            parameters.Add("Cost", monthlyBill.Cost);
            parameters.Add("Date", monthlyBill.Date);
            var procResponse = new Instance <dynamic>().Execute("dbo.updateMonthlyBills", parameters);

            if (procResponse != null)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 18
0
        public bool InsertMonthly(MonthlyBill monthlyBill, string ASPUser)
        {
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("Bill", monthlyBill.Bill);
            parameters.Add("Cost", monthlyBill.Cost);
            parameters.Add("Date", monthlyBill.Date);
            parameters.Add("UserID", ASPUser); // TODO use ASP User once login added

            var procResponse = new Instance <dynamic>().Execute("dbo.insertMonthlyBills", parameters);

            if (procResponse != null)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 19
0
 public static bool SaveMonthlyBill(MonthlyBill bill)
 {
     using (var ctx = new EconomyContext())
     {
         try
         {
             ctx.MonthlyBills.Attach(bill);
             ctx.Entry(bill).State = System.Data.Entity.EntityState.Modified;
             ctx.SaveChanges();
             return(true);
         }
         catch (Exception ex)
         {
             return(false);
         }
     }
 }
Ejemplo n.º 20
0
        public ActionResult Create([Bind(Include = "id,Bill,Cost,Date,BillAlias")] MonthlyBill monthlyBill)
        {
            var claimsIdentity = User.Identity as ClaimsIdentity;

            var userIdClaim = claimsIdentity.Claims
                              .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);

            if (userIdClaim != null)
            {
                userIdValue = userIdClaim.Value;
            }
            else
            {
                userIdValue = "tempuser";
            }
            if (ModelState.IsValid)
            {
                monthlyBill.UserID = userIdValue;
                db.MonthlyBills.Add(monthlyBill);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(monthlyBill));
        }