public int Delete(TestimonialModel objectModel) { int count = -1; // check the langauge id if exists in another table //if (!context.tblMemberships.Any(o => o.MembershipId == objectModel.FaqCategoryId)) //{ // count = -2; // return count; //} tblTestimonial tblTestimonialDb = new tblTestimonial(); tblTestimonialDb.TestimonialId = objectModel.TestimonialId; context.Entry(tblTestimonialDb).State = EntityState.Deleted; count = context.SaveChanges(); if (count == 1) { count = 0; } else { count = -1; } return(count); }
public EditTestimonialModel(tblTestimonial testimonialObj) { this.ID = testimonialObj.ID; this.Title = testimonialObj.Title; this.Description = testimonialObj.Description; this.IsActive = testimonialObj.IsActive; this.ActivatedOn = testimonialObj.ActivatedOn; this.IsDeleted = testimonialObj.IsDeleted; this.DeletedOn = testimonialObj.DeletedOn; this.AddedOn = testimonialObj.AddedOn; }
public int update(TestimonialModel objectModel) { tblTestimonial tblTestimonialDb = new tblTestimonial(); tblTestimonialDb.TestimonialId = objectModel.TestimonialId; tblTestimonialDb.AuthorName = objectModel.AuthorName; tblTestimonialDb.Designation = objectModel.Designation; tblTestimonialDb.Description = objectModel.Description; tblTestimonialDb.DisplayOrder = objectModel.DisplayOrder; tblTestimonialDb.Status = objectModel.Status; tblTestimonialDb.ImageFile = objectModel.ImageFile; tblTestimonialDb.ActualImageFile = objectModel.ActualImageFile; if (objectModel.TestimonialId > 0) { tblTestimonialDb.ModifiedBy = AdminSessionData.AdminUserId; tblTestimonialDb.ModifiedOn = DateTime.Now; tblTestimonialDb.ModifiedFromIP = HttpContext.Current.Request.UserHostAddress; context.tblTestimonials.Attach(tblTestimonialDb); context.Entry(tblTestimonialDb).Property(x => x.AuthorName).IsModified = true; context.Entry(tblTestimonialDb).Property(x => x.Designation).IsModified = true; context.Entry(tblTestimonialDb).Property(x => x.Description).IsModified = true; context.Entry(tblTestimonialDb).Property(x => x.DisplayOrder).IsModified = true; context.Entry(tblTestimonialDb).Property(x => x.ImageFile).IsModified = true; context.Entry(tblTestimonialDb).Property(x => x.ActualImageFile).IsModified = true; context.Entry(tblTestimonialDb).Property(x => x.Status).IsModified = true; context.Entry(tblTestimonialDb).Property(x => x.ModifiedBy).IsModified = true; context.Entry(tblTestimonialDb).Property(x => x.ModifiedOn).IsModified = true; context.Entry(tblTestimonialDb).Property(x => x.ModifiedFromIP).IsModified = true; } else { tblTestimonialDb.CreatedBy = AdminSessionData.AdminUserId; tblTestimonialDb.CreatedOn = DateTime.Now; tblTestimonialDb.CreatedFromIp = HttpContext.Current.Request.UserHostAddress; context.tblTestimonials.Add(tblTestimonialDb); } int count = context.SaveChanges(); if (count == 1) { count = 0; } else { count = -1; } return(count); }
public int ActDeact(TestimonialModel objectModel) { tblTestimonial tblTestimonialDb = new tblTestimonial(); tblTestimonialDb.TestimonialId = objectModel.TestimonialId; tblTestimonialDb.Status = objectModel.Status; context.tblTestimonials.Attach(tblTestimonialDb); context.Entry(tblTestimonialDb).Property(x => x.Status).IsModified = true; int count = context.SaveChanges(); if (count == 1) { count = 0; } else { count = -1; } return(count); }
ActionOutput ITestimonialManager.AddUpdateTestimonial(AddTestimonialModel testimonialModel) { try { if (testimonialModel.ID > 0) { var testimonial = Context.tblTestimonials.Where(z => z.ID == testimonialModel.ID && z.IsDeleted != true).FirstOrDefault(); if (testimonial != null) { testimonial.Title = testimonialModel.Title; if (testimonialModel.Image == null) { testimonial.Image = testimonialModel.ImageName; } else { testimonial.Image = Utilities.SaveImage(testimonialModel.Image, AppDefaults.TestimonialsPath, AppDefaults.TestimonialsThumbPath); } testimonial.Name = testimonialModel.Name; testimonial.Description = testimonialModel.Description; Context.SaveChanges(); return(new ActionOutput { Status = ActionStatus.Successfull, Message = "Sucessfully Updated." }); } else { return(new ActionOutput { Status = ActionStatus.Error, Message = "No testimonial found." }); } } else { var newTestimonial = new tblTestimonial(); newTestimonial.Title = testimonialModel.Title; newTestimonial.Name = testimonialModel.Name; newTestimonial.Description = testimonialModel.Description; newTestimonial.IsActive = testimonialModel.IsActive; newTestimonial.ActivatedOn = DateTime.UtcNow; newTestimonial.AddedOn = DateTime.UtcNow; newTestimonial.Image = Utilities.SaveImage(testimonialModel.Image, AppDefaults.TestimonialsPath, AppDefaults.TestimonialsThumbPath); newTestimonial.IsDeleted = testimonialModel.IsDeleted; newTestimonial.DeletedOn = testimonialModel.DeletedOn; Context.tblTestimonials.Add(newTestimonial); Context.SaveChanges(); return(new ActionOutput { Status = ActionStatus.Successfull, Message = "Sucessfully Added." }); } } catch (Exception ex) { return(new ActionOutput { Status = ActionStatus.Error, Message = "Internal Server error." }); } }