Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            UserFileMaster userFileMaster = db.UserFileMasters.Find(id);

            db.UserFileMasters.Remove(userFileMaster);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult Edit([Bind(Include = "ID,LastName,FirstName,Email,Password,UserRoleMasterID,UserDetailMaster")] UserMaster userMaster, HttpPostedFileBase upload)
        {
            ///Another way to perfrom multiple table update is using AutoMapper. Need to discuss pro and cons.
            ///http://stackoverflow.com/questions/15336248/entity-framework-5-updating-a-record

            UserMaster original = uow.UserRepository.Get(
                filter: u => u.ID == userMaster.ID,
                includeProperties: "UserDetailMaster,UserFiles"
                ).SingleOrDefault();


            if (ModelState.IsValid)
            {
                original.LastName  = userMaster.LastName;
                original.FirstName = userMaster.FirstName;
                original.Password  = userMaster.Password;
                original.Email     = userMaster.Email;
                if (upload != null && upload.ContentLength > 0)
                {
                    if (original.UserFiles != null)
                    {
                        UserFileMaster ufm = uow.UserFileRepository.GetFileByUserID(original.ID);
                        uow.UserFileRepository.Delete(ufm);
                        uow.Save();
                    }
                    var image = new UserFileMaster
                    {
                        FileName     = System.IO.Path.GetFileName(upload.FileName),
                        FileType     = FileType.ProfilePic,
                        ContentType  = upload.ContentType,
                        UserMasterID = userMaster.ID
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        image.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    original.UserFiles = image;
                }

                if (original.UserDetailMaster != null)
                {
                    UserDetailMaster udm = uow.UserDetailRepository.GetUserDetailByUserID(original.ID);
                    uow.UserDetailRepository.Delete(udm);
                    uow.Save();
                }
                original.UserDetailMaster = userMaster.UserDetailMaster;
                original.UserDetailMaster.UserMasterID = userMaster.ID;
                original.UserRoleMasterID = 1;
                uow.UserRepository.Update(original);
                uow.Save();
            }
            //ViewBag.UserRoleMasterID = new SelectList(db.UserRoleMasters, "ID", "Name", userMaster.UserRoleMasterID);
            return(View(original));
        }
Beispiel #3
0
 public ActionResult Edit([Bind(Include = "ID,FileName,ContentType,Content,FileType,UserMasterID")] UserFileMaster userFileMaster)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userFileMaster).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserMasterID = new SelectList(db.UserMasters, "ID", "LastName", userFileMaster.UserMasterID);
     return(View(userFileMaster));
 }
Beispiel #4
0
        // GET: UserFileMaster/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserFileMaster userFileMaster = db.UserFileMasters.Find(id);

            if (userFileMaster == null)
            {
                return(HttpNotFound());
            }
            return(View(userFileMaster));
        }
Beispiel #5
0
        // GET: UserFileMaster/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserFileMaster userFileMaster = db.UserFileMasters.Find(id);

            if (userFileMaster == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserMasterID = new SelectList(db.UserMasters, "ID", "LastName", userFileMaster.UserMasterID);
            return(View(userFileMaster));
        }