Ejemplo n.º 1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            try
            {
                DepotRecord depotRecord = await db.DepotRecords.FindAsync(id);

                db.DepotRecords.Remove(depotRecord);
                await db.SaveChangesAsync();

                var controller = DependencyResolver.Current.GetService <LogRecordsController>();
                controller.ControllerContext = new ControllerContext(this.Request.RequestContext, controller);
                controller.Create(
                    new LogRecord
                {
                    UserId       = this.User.Identity.GetUserId(),
                    DateOfRecord = DateTime.Now,
                    Action       = LogAction.SLETTING,
                    InfoMessage  = string.Format(
                        "SLETTING. INFO: Utstyr-ID: {0}; Type-ID: {1}; Utløpsdato: {2}; Antall opprinnelig: {3}; Antall igjen: {4}",
                        depotRecord.Id,
                        depotRecord.EquipmentCodeId,
                        (depotRecord.ExpirationDate != null) ? depotRecord.ExpirationDate.Value.ToShortDateString() : "Ingen",
                        depotRecord.QuantityOriginal
                        , depotRecord.QuantityLeft
                        )
                });
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View("Error"));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DepotRecord depotRecord = await db.DepotRecords.FindAsync(id);

            if (depotRecord == null)
            {
                return(HttpNotFound());
            }
            ViewBag.dropDownList = new SelectList(db.Equipments.OrderBy(r => r.NameAndType), "Id", "NameAndType", depotRecord.EquipmentCodeId);
            return(View(depotRecord));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,EquipmentCodeId,ExpirationDate,DateOfRecord,QuantityOriginal,QuantityLeft,Information")] DepotRecord depotRecord)
        {
            try
            {
                if (depotRecord.QuantityLeft > depotRecord.QuantityOriginal)
                {
                    ModelState.AddModelError(string.Empty, "Gjenværende antallet kan ikke være større enn det opprinnelige antallet!");
                    ViewBag.dropDownList = new SelectList(db.Equipments.OrderBy(r => r.NameAndType), "Id", "NameAndType", depotRecord.EquipmentCodeId);
                    return(View(depotRecord));
                }
                if (ModelState.IsValid)
                {
                    db.Entry(depotRecord).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    var controller = DependencyResolver.Current.GetService <LogRecordsController>();
                    controller.ControllerContext = new ControllerContext(this.Request.RequestContext, controller);
                    controller.Create(
                        new LogRecord
                    {
                        UserId       = this.User.Identity.GetUserId(),
                        DateOfRecord = DateTime.Now,
                        Action       = LogAction.ENDRING,
                        InfoMessage  = string.Format(
                            "ENDRING. NY INFO: Utstyr-ID: {0}; Type-ID: {1}; Utløpsdato: {2}; Antall opprinnelig: {3}; Antall igjen: {4}",
                            depotRecord.Id,
                            depotRecord.EquipmentCodeId,
                            (depotRecord.ExpirationDate != null) ? depotRecord.ExpirationDate.Value.ToShortDateString() : "Ingen",
                            depotRecord.QuantityOriginal
                            , depotRecord.QuantityLeft
                            )
                    });
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                ViewBag.dropDownList = new SelectList(db.Equipments.OrderBy(r => r.NameAndType), "Id", "NameAndType", depotRecord.EquipmentCodeId);
                return(View(depotRecord));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Noe gikk galt. Vennligst prøv igjen.");
                ViewBag.dropDownList = new SelectList(db.Equipments.OrderBy(r => r.NameAndType), "Id", "NameAndType", depotRecord.EquipmentCodeId);
                return(View(depotRecord));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Create([Bind(Include = "EquipmentCodeId,ExpirationDate,QuantityOriginal,Information")] DepotRecord depotRecord)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    depotRecord.QuantityLeft = depotRecord.QuantityOriginal;
                    depotRecord.DateOfRecord = DateTime.Now;
                    depotRecord = db.DepotRecords.Add(depotRecord);
                    await db.SaveChangesAsync();

                    var controller = DependencyResolver.Current.GetService <LogRecordsController>();
                    controller.ControllerContext = new ControllerContext(this.Request.RequestContext, controller);
                    controller.Create(
                        new LogRecord
                    {
                        UserId       = this.User.Identity.GetUserId(),
                        DateOfRecord = DateTime.Now,
                        Action       = LogAction.NYTT_UTSTYR,
                        InfoMessage  = string.Format(
                            "NYTT UTSTYR. Utstyr-ID: {0}; Type-ID: {1}; Utløpsdato: {2}; Antall opprinnelig: {3}",
                            depotRecord.Id,
                            depotRecord.EquipmentCodeId,
                            (depotRecord.ExpirationDate != null) ? depotRecord.ExpirationDate.Value.ToShortDateString() : "Ingen",
                            depotRecord.QuantityOriginal
                            )
                    });
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Noe gikk galt. Vennligst prøv igjen.");
                    ViewBag.selectList = new SelectList(db.Equipments.OrderBy(r => r.NameAndType), "Id", "NameAndType");
                    return(View(depotRecord));
                }
            }
            ViewBag.selectList = new SelectList(db.Equipments.OrderBy(r => r.NameAndType), "Id", "NameAndType");
            return(View(depotRecord));
        }