public async Task <ResponseModel> Item(int id) { ResponseModel response = new ResponseModel(); try { TrainingCenter md = await _context.TrainingCenterRepository.FirstOrDefaultAsync(m => m.Id == id); TrainingCenterModel model = new TrainingCenterModel() { Id = md.Id, Name = md.Name, Description = md.Description, IsActive = md.IsActive, RowVersion = md.RowVersion }; response.Result = model; } catch (Exception ex) { throw ex; } return(response); }
public async Task <ResponseModel> Delete(TrainingCenterModel model) { ResponseModel response = new ResponseModel(); try { TrainingCenter md = await _context.TrainingCenterRepository.FirstOrDefaultAsync(m => m.Id == model.Id); if (!md.RowVersion.SequenceEqual(model.RowVersion)) { response.ResponseStatus = Core.CommonModel.Enums.ResponseStatus.OutOfDateData; return(response); } md.Deleted = true; md.UpdateBy = base.UserId; md.UpdateDate = DateTime.Now; _context.TrainingCenterRepository.Update(md); await _context.SaveChangesAsync(); } catch (Exception ex) { throw ex; } return(response); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Code")] TrainingCenter TrainingCenter) { if (id != TrainingCenter.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _trainingCenterRepository.UpdateTrainingCenter(TrainingCenter); _trainingCenterRepository.Save(); } catch (DbUpdateConcurrencyException) { if (!trainingCenterExists(TrainingCenter.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(TrainingCenter)); }
public ActionResult Create([Bind(Include = "Id,Addres,Phone,Email,Organization,Description,Logo,Url,HHCityId")] TrainingCenter trainingcenter, HttpPostedFileBase uploadImage) { if (ModelState.IsValid) { if (uploadImage != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(uploadImage.InputStream)) imageData = binaryReader.ReadBytes(uploadImage.ContentLength); // установка массива байтов trainingcenter.Logo = imageData; trainingcenter.LogoContentType = uploadImage.ContentType; } db.TrainingCenters.Add(trainingcenter); db.SaveChanges(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(appDb)); var role = new IdentityRole { Name = "admin_" + trainingcenter.Url }; roleManager.Create(role); return(RedirectToAction("Index")); } return(View(trainingcenter)); }
public ActionResult DeleteConfirmed(int id) { TrainingCenter trainingCenter = db.TrainingCenters.Find(id); db.TrainingCenters.Remove(trainingCenter); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "TrainingCenterId,TpId,CenterCode,CenterName,Phone1,Phone2,City,State,AddressLine1,AddressLine2,Zip,IsActive")] TrainingCenter trainingCenter) { if (ModelState.IsValid) { db.Entry(trainingCenter).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trainingCenter)); }
public async Task <IActionResult> Create([Bind("ID,Name,Code")] TrainingCenter TrainingCenter) { if (ModelState.IsValid) { _trainingCenterRepository.InsertTrainingCenter(TrainingCenter); _trainingCenterRepository.Save(); return(RedirectToAction(nameof(Index))); } return(View(TrainingCenter)); }
public ActionResult Create([Bind(Include = "TrainingCenterId,TpId,CenterCode,CenterName,Phone1,Phone2,City,State,AddressLine1,AddressLine2,Zip,IsActive")] TrainingCenter trainingCenter) { if (ModelState.IsValid) { db.TrainingCenters.Add(trainingCenter); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trainingCenter)); }
public ActionResult Create(TrainingCenter model, string command) { try { if (ModelState.IsValid) { model.Created_By = User.Identity.Name; model.Created_Date = DateTime.Now.Date; var tra_center = dbcontext.TrainingCenter.Add(model); dbcontext.SaveChanges(); //=================================check for alert================================== var get_result_check = HR.Controllers.check.check_alert("training center", HR.Models.user.Action.Create, HR.Models.user.type_field.form); if (get_result_check != null) { var inbox = new Models.user.Alert_inbox { send_from_user_id = User.Identity.Name, send_to_user_id = get_result_check.send_to_ID_user, title = get_result_check.Subject, Subject = get_result_check.Message }; if (get_result_check.until != null) { if (get_result_check.until.Value.Year != 0001) { inbox.until = get_result_check.until; } } ApplicationDbContext dbcontext = new ApplicationDbContext(); dbcontext.Alert_inbox.Add(inbox); dbcontext.SaveChanges(); } //=================================================================================== if (command == "Submit") { return(RedirectToAction("Create", "Postalcode", new { id = tra_center.ID })); } return(RedirectToAction("Index")); } else { return(View(model)); } } catch (DbUpdateException e) { TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TrainingCenter trainingcenter = db.TrainingCenters.Find(id); if (trainingcenter == null) { return(HttpNotFound()); } return(View(trainingcenter)); }
public static TrainingCenter getTc(string tcUrl, TrainingCentersDBEntities db) { try { TrainingCenter tc = db.TrainingCenters.Where(a => a.Url == tcUrl).ToList().First(); if (tc == null) { throw new HttpException(404, "NotFound"); } return(tc); } catch (Exception ex) { throw new HttpException(404, "NotFound"); } }
public void Joining() { List <User> users = User.GetUsersList(); List <TrainingCenter> centers = TrainingCenter.GetTrainingCentersList(); var userTrainingCenterQuery = from user in users join center in centers on user.Country equals center.Country select new { UserName = user.Name, TrainingCenterName = center.Name }; Console.WriteLine("================================"); Console.WriteLine("These are the users with their local centers:"); foreach (var userCenter in userTrainingCenterQuery) { Console.WriteLine("User: {0}, Local Training Center: {1}", userCenter.UserName, userCenter.TrainingCenterName); } }
public ActionResult DeleteConfirmed(int id) { TrainingCenter trainingcenter = db.TrainingCenters.Find(id); var roleName = "admin_" + trainingcenter.Url; var role = appDb.Roles.SingleOrDefault(r => r.Name == roleName); try { appDb.Roles.Remove(role); } catch { } appDb.SaveChanges(); db.TrainingCenters.Remove(trainingcenter); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create() { ////// var modell = new TrainingCenter(); var stru = dbcontext.StructureModels.FirstOrDefault(m => m.All_Models == ChModels.Talent_Development).Structure_Code; var model = dbcontext.TrainingCenter.ToList(); if (model.Count() == 0) { modell.TrainingCenters_Code = stru + "1"; } else { modell.TrainingCenters_Code = stru + (model.LastOrDefault().ID + 1).ToString(); } ///// return(View(modell)); }
public ActionResult Edit([Bind(Include = "Id,Addres,Phone,Email,Organization,Description,Logo,Url,HHCityId")] TrainingCenter trainingcenter, HttpPostedFileBase uploadImage) { if (ModelState.IsValid) { if (uploadImage != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(uploadImage.InputStream)) imageData = binaryReader.ReadBytes(uploadImage.ContentLength); // установка массива байтов trainingcenter.Logo = imageData; trainingcenter.LogoContentType = uploadImage.ContentType; } db.Entry(trainingcenter).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trainingcenter)); }
public async Task <ResponseModel> Insert(TrainingCenterModel model) { ResponseModel response = new ResponseModel(); try { TrainingCenter md = new TrainingCenter(); md.Name = model.Name; md.Description = model.Description; md.IsActive = model.IsActive; md.CreateBy = base.UserId; md.CreateDate = DateTime.Now; await _context.TrainingCenterRepository.AddAsync(md).ConfigureAwait(true); await _context.SaveChangesAsync(); } catch (Exception ex) { throw ex; } return(response); }
/// <summary> /// حذف رکورد مرکز آموزشی /// </summary> /// <param name="entity">رکورد مرکز آموزشی</param> public void DeleteTrainingCenter(TrainingCenter entity) => _context.Entry(entity).State = EntityState.Deleted;
/// <summary> /// ثبت رکورد جدید مرکز آموزشی /// </summary> /// <param name="entity">رکورد مرکز آموزشی</param> public void InsertTrainingCenter(TrainingCenter entity) => _dbSet.Add(entity);
/// <summary> /// ویرایش رکورد مرکز آموزشی /// </summary> /// <param name="entity">رکورد مرکز آموزشی</param> public void UpdateTrainingCenter(TrainingCenter entity) => _context.Entry(entity).State = EntityState.Modified;
protected override void OnActionExecuting(ActionExecutingContext ctx) { trainingCenter = TCHelper.getTc(RouteData.Values["tc"].ToString(), db); }