コード例 #1
0
        public IHttpActionResult PutPetOwnerProfile(int id, PetOwnerProfile petOwnerProfile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != petOwnerProfile.profileId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public ActionResult EditDetail(PetOwnerProfile info, HttpPostedFileBase file, Image ImageModel)
        {
            int imageid;
            PODBProjectEntities entities = new PODBProjectEntities();
            String userId = User.Identity.GetUserId();

            PostPhoto photo = new PostPhoto();
            String    path  = photo.PostPhotoPetOwner(file);

            if (file != null)
            {
                imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;
            }
            else
            {
                imageid = entities.PetOwnerProfiles.Where(e => e.Id.Equals(userId)).FirstOrDefault().imageID;
            }

            using (PODBProjectEntities image = new PODBProjectEntities())
            {
                ImageModel.imageID               = imageid;
                ImageModel.imagePath             = path;
                ImageModel.imageType             = "PetOwnerProfile";
                entities.Entry(ImageModel).State = EntityState.Modified;
                entities.SaveChanges();
            }

            using (entities)
            {
                var result = entities.PetOwnerProfiles.SingleOrDefault(e => e.Id == userId);
                if (result != null)
                {
                    if (info.subdivision == null)
                    {
                        info.subdivision = "none";
                    }
                    else
                    {
                    }
                    var user = new PetOwnerProfile()
                    {
                        Id            = userId,
                        fullName      = info.fullName,
                        gender        = info.gender,
                        street        = info.street,
                        subdivision   = info.subdivision,
                        barangay      = info.barangay,
                        contactNumber = info.contactNumber,
                        email         = entities.AspNetUsers.Where(e => e.Id.Equals(userId)).FirstOrDefault().Email,
                        registerDate  = entities.PetOwnerProfiles.Where(e => e.Id.Equals(userId)).FirstOrDefault().registerDate,
                        updateDate    = DateTime.Now,
                        imageID       = imageid
                    };
                    entities.SaveChanges();
                }
                return(RedirectToAction("ViewDetail", "Manage"));
            }
        }
コード例 #3
0
        public ActionResult Edit(int id, PetProfile petProfile, HttpPostedFileBase file)
        {
            int imageid;
            PODBProjectEntities entities = new PODBProjectEntities();
            String userId = User.Identity.GetUserId();

            PostPhoto photo = new PostPhoto();
            String    path  = photo.PostPhotoPet(file);

            if (file != null)
            {
                imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;
            }
            else
            {
                imageid = entities.Announcements.Where(e => e.announceId.Equals(id)).FirstOrDefault().imageID;
            }
            try
            {
                using (PODBProjectEntities edit = new PODBProjectEntities())
                {
                    petProfile.Id                = User.Identity.GetUserId();
                    petProfile.imageID           = 1;
                    edit.Entry(petProfile).State = EntityState.Modified;
                    edit.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(View());
            }
        }
コード例 #4
0
        public ActionResult Create(Announcement announce, HttpPostedFileBase file)
        {
            PODBProjectEntities entities = new PODBProjectEntities();

            PostPhoto photo = new PostPhoto();
            String    path  = photo.PostPhotoAnnouncement(file);

            int ImageID = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;

            try
            {
                using (PODBProjectEntities announcement = new PODBProjectEntities())
                {
                    announce.Id           = User.Identity.GetUserId();
                    announce.announceDate = DateTime.Now;
                    announce.imageID      = ImageID;
                    entities.Announcements.Add(announce);
                    entities.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #5
0
ファイル: PostPhoto.cs プロジェクト: Sentinel927/PODBProject
        public String PostPhotoAnnouncement(HttpPostedFileBase file)
        {
            PODBProjectEntities entities = new PODBProjectEntities();
            String imagePath             = "";
            var    path = "";

            if (file != null)
            {
                if (file.ContentLength > 0)
                {
                    if (Path.GetExtension(file.FileName).ToLower() == ".jpg" ||
                        Path.GetExtension(file.FileName).ToLower() == ".png" ||
                        Path.GetExtension(file.FileName).ToLower() == ".jpeg")
                    {
                        imagePath = "/Content/images/Announcement/" + file.FileName;
                        path      = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/images/Announcement/"), file.FileName);
                        file.SaveAs(path);
                        entities.Images.Add(new Image()
                        {
                            imagePath = imagePath,
                            imageType = "Announcement",
                        });
                        entities.SaveChanges();
                    }
                }
            }
            return(imagePath);
        }
コード例 #6
0
 public ActionResult AddOrEditReports(Report report)
 {
     using (PODBProjectEntities entities = new PODBProjectEntities())
     {
         if (report.reportId == 0)
         {
             entities.Reports.Add(report);
             entities.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             entities.Entry(report).State = EntityState.Modified;
             entities.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
コード例 #7
0
 public ActionResult AddOrEditViolations(Violation violation)
 {
     using (PODBProjectEntities entities = new PODBProjectEntities())
     {
         if (violation.violationId == 0)
         {
             entities.Violations.Add(violation);
             entities.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             entities.Entry(violation).State = EntityState.Modified;
             entities.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
コード例 #8
0
 public ActionResult AddOrEdit(PetOwnerProfile po)
 {
     using (PODBProjectEntities db = new PODBProjectEntities())
     {
         if (po.profileId == 0)
         {
             db.PetOwnerProfiles.Add(po);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(po).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
コード例 #9
0
 public ActionResult DeleteViolations(int id)
 {
     using (PODBProjectEntities entities = new PODBProjectEntities())
     {
         Violation emp = entities.Violations.Where(x => x.violationId == id).FirstOrDefault <Violation>();
         entities.Violations.Remove(emp);
         entities.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #10
0
 public ActionResult Delete(int id)
 {
     using (PODBProjectEntities db = new PODBProjectEntities())
     {
         PetOwnerProfile emp = db.PetOwnerProfiles.Where(x => x.profileId == id).FirstOrDefault <PetOwnerProfile>();
         db.PetOwnerProfiles.Remove(emp);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #11
0
        public ActionResult PetOwnerProfile(PetOwnerProfile info, HttpPostedFileBase file, Image ImageModel)
        {
            PODBProjectEntities entities = new PODBProjectEntities();
            String userId = User.Identity.GetUserId();

            PostPhoto photo = new PostPhoto();
            String    path  = photo.PostPhotoPetOwner(file);

            int    imageid = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;
            string Email   = entities.AspNetUsers.Where(e => e.Id.Equals(userId)).FirstOrDefault().Email;

            if (info.subdivision == null)
            {
                info.subdivision = "N/A";
            }
            else
            {
            }
            var user = new PetOwnerProfile()
            {
                Id            = userId,
                fullName      = info.fullName,
                gender        = info.gender,
                street        = info.street,
                subdivision   = info.subdivision,
                barangay      = info.barangay,
                contactNumber = info.contactNumber,
                email         = Email,
                registerDate  = DateTime.Now,
                updateDate    = DateTime.Now,
                imageID       = imageid
            };

            entities.PetOwnerProfiles.Add(user);
            entities.SaveChanges();

            if (!entities.AspNetUsers.Where(e => e.Email.Equals(Email)).FirstOrDefault().EmailConfirmed)
            {
                Session.Abandon();
                AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                ModelState.AddModelError("", "You need to confirm your email address");
                return(RedirectToAction("ConfirmBeforeLogin", "Account"));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #12
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         using (PODBProjectEntities entities = new PODBProjectEntities())
         {
             PetProfile petProfile = entities.PetProfiles.Where(e => e.petId.Equals(id)).FirstOrDefault();
             entities.PetProfiles.Remove(petProfile);
             entities.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         return(View());
     }
 }
コード例 #13
0
        public ActionResult Delete(int id, Announcement announce)
        {
            PODBProjectEntities entities = new PODBProjectEntities();

            try
            {
                Announcement announcement = entities.Announcements.Find(id);
                entities.Announcements.Remove(announcement);
                entities.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch (NullReferenceException)
            {
                return(View());
            }
        }
コード例 #14
0
        public ActionResult CreateAnnouncement(AnnouncementModel announce)
        {
            string UserID = User.Identity.GetUserId();
            PODBProjectEntities entities     = new PODBProjectEntities();
            Announcement        announcement = new Announcement()
            {
                announceTitle = announce.announceTitle,
                announceText  = announce.announceText,
                announceDate  = DateTime.Now,
                Id            = UserID,
                imageID       = 1
            };

            entities.Announcements.Add(announcement);
            entities.SaveChanges();
            return(View());
        }
コード例 #15
0
        public ActionResult Create(PetProfileModel petProfile, HttpPostedFileBase file)
        {
            PODBProjectEntities entities = new PODBProjectEntities();
            PostPhoto           photo    = new PostPhoto();
            String path = photo.PostPhotoPet(file);

            int ImageID = entities.Images.Where(e => e.imagePath.Equals(path)).FirstOrDefault().imageID;

            if (petProfile.mChipId == null)
            {
                petProfile.mChipId = "Not Microchipped";
            }
            var pet = new PetProfile
            {
                Id           = User.Identity.GetUserId(),
                imageID      = ImageID,
                petName      = petProfile.petName,
                petType      = petProfile.petType,
                petBreed     = petProfile.petBreed,
                gender       = petProfile.gender,
                mChipId      = petProfile.mChipId,
                mChipStatus  = petProfile.mChipStatus,
                nueterStatus = petProfile.nueterStatus
            };

            entities.PetProfiles.Add(pet);
            try
            {
                entities.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                    }
                }
            }
            return(RedirectToAction("Index"));
        }