Esempio n. 1
0
        public IActionResult Create(CPropertyViewModel pmodel)
        {
            if (ModelState.IsValid == false)
            {
                ViewBag.Departments = db.TUserDepartments.ToList();
                ViewBag.check       = db.TLostAndFoundCheckStatuses.ToList();
                ViewBag.subject     = db.TLostAndFoundSubjects.ToList();
                ViewBag.category    = db.TLostAndFoundCategories.ToList();
                ViewBag.cphone      = db.TUsers.ToList();
                return(View(pmodel));
            }

            if (pmodel.image != null)
            {
                pmodel.CPropertyPhoto = uploadImage(pmodel.image);
            }

            db.TLostAndFounds.Add(new TLostAndFound
            {
                CDeparmentId           = pmodel.CDeparmentId,
                CEmployeeId            = pmodel.CEmployeeId,
                CLostAndFoundDate      = DateTime.UtcNow.AddHours(8),
                CLostAndFoundSpace     = pmodel.CLostAndFoundSpace,
                CPhone                 = pmodel.CPhone,
                CProperty              = pmodel.CProperty,
                CPropertyCategoryId    = pmodel.CPropertyCategoryId,
                CPropertyPhoto         = pmodel.CPropertyPhoto,
                CPropertySubjectId     = pmodel.CPropertySubjectId,
                CPropertyCheckStatusId = pmodel.CPropertyCheckStatusId,
                CtPropertyDescription  = pmodel.CtPropertyDescription
            });

            db.SaveChanges();
            return(RedirectToAction("List"));
        }
Esempio n. 2
0
        public ActionResult Edit(CPropertyViewModel pmodel)
        {
            if (ModelState.IsValid == false)
            {
                ViewBag.Departments = db.TUserDepartments.ToList();
                ViewBag.check       = db.TLostAndFoundCheckStatuses.ToList();
                ViewBag.subject     = db.TLostAndFoundSubjects.ToList();
                ViewBag.category    = db.TLostAndFoundCategories.ToList();
                ViewBag.cphone      = db.TUsers.ToList();
                return(View(pmodel));
            }

            var entity = db.TLostAndFounds.Where(e => e.CPropertyId == pmodel.CPropertyId).FirstOrDefault();

            if (entity == null)
            {
                return(RedirectToAction("List"));
            }

            entity.CDeparmentId           = pmodel.CDeparmentId;
            entity.CEmployeeId            = pmodel.CEmployeeId;
            entity.CPropertyId            = pmodel.CPropertyId;
            entity.CProperty              = pmodel.CProperty;
            entity.CPropertyCategoryId    = pmodel.CPropertyCategoryId;
            entity.CLostAndFoundSpace     = pmodel.CLostAndFoundSpace;
            entity.CPropertySubjectId     = pmodel.CPropertySubjectId;
            entity.CtPropertyDescription  = pmodel.CtPropertyDescription;
            entity.CPropertyCheckStatusId = pmodel.CPropertyCheckStatusId;
            entity.CLostAndFoundDate      = pmodel.CLostAndFoundDate;
            entity.CPhone = pmodel.CPhone;

            if (pmodel.image != null)
            {
                entity.CPropertyPhoto = uploadImage(pmodel.image);
            }

            db.SaveChanges();
            return(RedirectToAction("List"));
        }
Esempio n. 3
0
        public IActionResult Edit(int?id)
        {
            if (id.HasValue == false)
            {
                return(RedirectToAction("List"));
            }

            TLostAndFound tf = db.TLostAndFounds.Where(e => e.CPropertyId == id).FirstOrDefault();

            if (tf == null)
            {
                return(RedirectToAction("List"));
            }

            var result = new CPropertyViewModel
            {
                CPropertyId            = tf.CPropertyId,
                CLostAndFoundDate      = tf.CLostAndFoundDate,
                CEmployeeId            = tf.CEmployeeId,
                CLostAndFoundSpace     = tf.CLostAndFoundSpace,
                CPropertyCheckStatusId = tf.CPropertyCheckStatusId,
                CPhone                = getUserPhone(),
                CPropertySubjectId    = tf.CPropertySubjectId,
                CtPropertyDescription = tf.CtPropertyDescription,
                CDeparmentId          = tf.CDeparmentId,
                CPropertyCategoryId   = tf.CPropertyCategoryId,
                CProperty             = tf.CProperty,
                CPropertyPhoto        = tf.CPropertyPhoto
            };

            ViewBag.Departments = db.TUserDepartments.ToList();
            ViewBag.check       = db.TLostAndFoundCheckStatuses.ToList();
            ViewBag.subject     = db.TLostAndFoundSubjects.ToList();
            ViewBag.category    = db.TLostAndFoundCategories.ToList();
            ViewBag.cphone      = db.TUsers.ToList();

            return(View(result));
        }