public CrResult <ChannelRoleDto> CreateChannel(ChannelCrDto channelDto, long userId) { var result = new CrResult <ChannelRoleDto>(); CheckData(result, channelDto); if (result.ActionResult == ActionResult.Success) { try { var c = _context.Channel.Add(Converter.ConvertToChannel(channelDto)); var userRole = UserRolesManager.AddUserRole(c.channel_id, userId, _adminId, _context); _context.SaveChanges(); userRole.Role = new Role { role_id = 0, role_name = "Admin" }; result.CreatedObject = Converter.ConvertToChannelRoleDto(userRole); } catch (DbUpdateException) { result.ActionResult = ActionResult.DatabaseError; } } return(result); }
public ActionResult Create([Bind(Include = "ID,DayID,ShiftID")] WorkDay workDay) { var workDayDate = db.Days.Where(x => x.ID == workDay.DayID).First(); var workDayShift = db.Shifts.Where(x => x.ID == workDay.ShiftID).First(); // Here comes code for connecting the date with workday. You come from the calendar and if you register a workday, then a event is created in the calendar. var kalender = new SchedulerContext(); Event newEvent = new Event(); newEvent.start_date = workDayDate.Date; newEvent.end_date = workDayDate.Date.AddHours(23); newEvent.text = workDayShift.ShiftName; kalender.Events.Add(newEvent); kalender.SaveChanges(); if (ModelState.IsValid) { var redirectID = workDay.ShiftID; db.WorkDays.Add(workDay); db.SaveChanges(); return(RedirectToAction("ShowShift", "WorkShift", new { id = redirectID })); } ViewBag.DayID = new SelectList(db.Days, "ID", "ID", workDay.DayID); ViewBag.ShiftID = new SelectList(db.Shifts, "ID", "ShiftName", workDay.ShiftID); return(View(workDay)); }
public CrResult <EventDto> CreateEvent(long userId, EventCrDto ev) { var res = new CrResult <EventDto>(); CheckEvent(ev, res); if (res.ActionResult == ActionResult.Success) { if (new UserRolesManager().CheckPermition(userId, ev.ChannelId, _addNewsPermitionId)) { try { var createdEv = _context.Event.Add(Converter.ConvertToEvent(ev)); _context.SaveChanges(); res.CreatedObject = Converter.ConvertToEventDto(createdEv); } catch (Exception) { res.ActionResult = ActionResult.DatabaseError; } } else { res.ActionResult = ActionResult.PermissionDenied; } } return(res); }
public Result InviteUser(long userId, string invitedUserNickname, long channelId) { var user = _context.User.FirstOrDefault(u => u.nickname == invitedUserNickname); var res = new Result(); if (user == null) { res.AddError(new Error(CheckStatus.IdDoesNotExist, nameof(invitedUserNickname))); return(res); } var invitedUserId = user.user_id; if (userId == invitedUserId || IsUserInChannel(invitedUserId, channelId) != null) { res.AddError(new Error(CheckStatus.ArgumentIsNotUnique, nameof(userId))); return(res); } if (CheckPermition(userId, channelId, _addUserPermitionId)) { AddUserRole(channelId, invitedUserId, _invitedUserRoleId, _context); try { _context.SaveChanges(); } catch (DbUpdateException) { res.ActionResult = ActionResult.DatabaseError; } } else { res.ActionResult = ActionResult.PermissionDenied; } return(res); }
public void Add(string name, string lector, int hoursPlan, List <Group> groups) { var findLector = DB.Lectors.Where(l => l.FIO == lector); if (check.Firmness(name) && check.IntegerValidation(hoursPlan) && findLector.Any()) { try { string groupsStr = ""; foreach (Group group in groups) { groupsStr += group.Name + ";"; } Lector lessonLector = DB.Lectors.Where(l => l.FIO.Equals(lector)).FirstOrDefault(); Discipline newRow = new Discipline(name, lessonLector, hoursPlan, groupsStr); var equalRecords = DB.Disciplines.Where(l => l.Name.Equals(name) && l.HoursPlan.Equals(hoursPlan) && l.Lector.FIO == lector); if (equalRecords.Any()) { MessageBox.Show("Такая дисциплина уже существует в базе", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DB.Disciplines.Add(newRow); DB.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Произошла ошибка добавления\n" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public ActionResult Create([Bind(Include = "ID,StartTime,EndTime")] Time time) { if (ModelState.IsValid) { db.Times.Add(time); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(time)); }
public ActionResult Create([Bind(Include = "ID,RoleName")] Role role) { if (ModelState.IsValid) { db.Roles.Add(role); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(role)); }
public ActionResult Create([Bind(Include = "ID,ShiftName")] Shift shift) { if (ModelState.IsValid) { db.Shifts.Add(shift); db.SaveChanges(); // Redirect to the WorkShift controller because it's the natural thing to do after you create a Shift. return(RedirectToAction("Create", "WorkShift", new { id = shift.ID })); } return(View(shift)); }
public ObjectResult Post([FromForm] WebAPIEvent apiEvent) { var newEvent = (SchedulerEvent)apiEvent; _context.Events.Add(newEvent); _context.SaveChanges(); return(Ok(new { tid = newEvent.Id, action = "inserted" })); }
public IHttpActionResult EditSchedulerEvent(int id, WebAPIEvent webAPIEvent) { var updatedSchedulerEvent = (SchedulerEvent)webAPIEvent; updatedSchedulerEvent.Id = id; db.Entry(updatedSchedulerEvent).State = EntityState.Modified; db.SaveChanges(); return(Ok(new { action = "updated" })); }
public ActionResult Edit(Customer customer, FullAddress fullAddress, FullName fullName) { if (ModelState.IsValid) { using (var db = new SchedulerContext()) { var result = db.Customers.SingleOrDefault(b => b.ID == customer.ID); var result2 = db.FullNames.SingleOrDefault(b => b.ID == fullName.ID); var result3 = db.FullAddresses.SingleOrDefault(b => b.ID == fullAddress.ID); var query = db.Customers.Count(); if (result != null & result2 != null & result3 != null) { Debug.WriteLine("-----------------------------------------------------------------------------------Made It"); result2 = fullName; result3 = fullAddress; result.Name = result2; result.HomeAddress = result3; db.SaveChanges(); } } } return(RedirectToAction("Index")); }
public ActionResult Edit(Employee employee, FullAddress fullAddress, FullName fullName, string JobTitle, string Groups) { if (ModelState.IsValid) { using (var db = new SchedulerContext()) { var result = db.Employees.SingleOrDefault(b => b.ID == employee.ID); var result2 = db.FullNames.SingleOrDefault(b => b.ID == fullName.ID); var result3 = db.FullAddresses.SingleOrDefault(b => b.ID == fullAddress.ID); if (result != null & result2 != null & result3 != null) { Debug.WriteLine("-----------------------------------------------------------------------------------Made It" + employee.ID); result2 = fullName; result3 = fullAddress; result.Name = result2; result.HomeAddress = result3; result.JobTitle = JobTitle; result.Groups = Groups; db.SaveChanges(); } } } return(RedirectToAction("Index")); }
public static void Seed(SchedulerContext context) { if (context.Events.Any()) { return; // DB has been seeded } var events = new List <SchedulerEvent>() { new SchedulerEvent { Name = "Event 1", StartDate = new DateTime(2019, 1, 15, 2, 0, 0), EndDate = new DateTime(2019, 1, 15, 4, 0, 0) }, new SchedulerEvent() { Name = "Event 2", StartDate = new DateTime(2019, 1, 17, 3, 0, 0), EndDate = new DateTime(2019, 1, 17, 6, 0, 0) }, new SchedulerEvent() { Name = "Multiday event", StartDate = new DateTime(2019, 1, 15, 0, 0, 0), EndDate = new DateTime(2019, 1, 20, 0, 0, 0) } }; events.ForEach(s => context.Events.Add(s)); context.SaveChanges(); }
public ActionResult Create([Bind(Include = "ID,ShiftID,PersonID,TimeID,RoleID")] WorkShift workShift) { if (ModelState.IsValid) { db.WorkShifts.Add(workShift); db.SaveChanges(); // Redirects to ShowShift with the specified ID. That way you only see the shift you are creating. return(RedirectToAction("ShowShift", "WorkShift", new { id = workShift.ShiftID })); } ViewBag.PersonID = new SelectList(db.People, "ID", "Name", workShift.PersonID); ViewBag.RoleID = new SelectList(db.Roles, "ID", "RoleName", workShift.RoleID); ViewBag.ShiftID = new SelectList(db.Shifts, "ID", "ShiftName", workShift.ShiftID); ViewBag.TimeID = new SelectList(db.Times, "ID", "StartTime", workShift.TimeID); return(View(workShift)); }
public ActionResult Create(Employee employee, FullAddress fullAddress, FullName fullName) { if (ModelState.IsValid) { employee.ID = Guid.NewGuid(); fullName.ID = employee.ID; fullAddress.ID = employee.ID; employee.Name = fullName; employee.HomeAddress = fullAddress; db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID = new SelectList(db.FullAddresses, "ID", "Street", employee.ID); ViewBag.ID = new SelectList(db.FullNames, "ID", "FirstName", employee.ID); return(View(employee)); }
public static void InsertAppointment(EFAppointment appt) { if (appt == null) { return; } SchedulerContext db = SchedulerSettingsHelper.LocalContext; db.EFAppointments.Local.Add(appt); db.SaveChanges(); }
public ObjectResult Post([FromForm] WebAPIRecurring apiEvent) { var newEvent = (SchedulerRecurringEvent)apiEvent; _context.RecurringEvents.Add(newEvent); _context.SaveChanges(); // delete a single occurrence from recurring series var resultAction = "inserted"; if (newEvent.RecType == "none") { resultAction = "deleted"; } return(Ok(new { tid = newEvent.Id, action = resultAction })); }
public ActionResult Create([Bind(Include = "ID,Date")] Day day) { var dates = db.Days.Select(x => x.Date); if (dates.Contains(day.Date)) { return(View(day)); } if (ModelState.IsValid) { if (!db.Days.Any(x => x.Date == day.Date)) { db.Days.Add(day); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(day)); }
public static void RemoveAppointment(EFAppointment appt) { if (appt == null) { return; } SchedulerContext db = SchedulerSettingsHelper.LocalContext; EFAppointment query = (EFAppointment)(from carSchedule in db.EFAppointments.Local where carSchedule.UniqueID == appt.UniqueID select carSchedule).SingleOrDefault(); db.EFAppointments.Remove(query); db.SaveChanges(); }
public ActionResult Create([Bind(Include = "ID")] Customer customer, string FirstName, string LastName, string MiddleName, string Country, string Province, string City, string Street, string PostalCode) { if (ModelState.IsValid) { FullName full = new FullName(); FullAddress fullA = new FullAddress(); Guid fullGUID = Guid.NewGuid(); Guid fullAGuid = Guid.NewGuid(); Debug.WriteLine("------------------------------------------------------------------------" + Country); full.FirstName = FirstName; full.LastName = LastName; full.ID = fullGUID; fullA.Country = Country; fullA.City = City; fullA.Street = Street; fullA.Province = Province; fullA.ID = fullAGuid; fullA.PostalCode = PostalCode; customer.ID = Guid.NewGuid(); customer.Name = full; customer.HomeAddress = fullA; full.person = customer; fullA.person = customer; db.FullNames.Add(full); db.FullAddresses.Add(fullA); db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public bool ClientConnected(ClientDevice client, string connectionId) { using (var dbContext = new SchedulerContext()) { if (!dbContext.Clients.Any(c => c.Name == client.Name)) { dbContext.Clients.Add(client); dbContext.SaveChanges(); Context.Value.Clients.All.clientAdded(client); } return(ClientsRegistry.Value.RegisterClient(client, connectionId)); } }
public CrResult <UserDto> Create(UserCrDto userCrDto) { var crResult = new CrResult <UserDto>(); CheckRegisterData(userCrDto, crResult, true, true); if (crResult.ActionResult == ActionResult.Success) { var user = Converter.ConvertToUser(userCrDto); var encryption = new HashEncryption(); encryption.HashPassword(user); try { var createdUser = _context.User.Add(user); _context.SaveChanges(); crResult.CreatedObject = Converter.ConvertToUserDto(createdUser); } catch (DbUpdateException) { crResult.ActionResult = ActionResult.DatabaseError; } } return(crResult); }
public void Add(string discipline, string group, string auditory, bool lecture) { var findDiscipline = DB.Disciplines.Where(l => l.Name == discipline); var findGroup = DB.Groups.Where(l => l.Name == group); var findAuditory = DB.Auditories.Where(l => l.Number == auditory); if (findDiscipline.Any() && findAuditory.Any() && findGroup.Any()) { try { Discipline lessonDiscipline = findDiscipline.FirstOrDefault(); Group lessonGroup = findGroup.FirstOrDefault(); Auditory lessonAuditory = findAuditory.FirstOrDefault(); Lesson newRow = new Lesson(lessonDiscipline, lessonGroup, lessonAuditory, lecture); DB.Lessons.Add(newRow); DB.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Произошла ошибка добавления\n" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
// Method that reads the uploaded excel and stores it in the data base. // POST: Person/Upload2 public ActionResult Upload2(FormCollection formCollection) { if (Request != null) { HttpPostedFileBase file = Request.Files["UploadedFile"]; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { string fileName = file.FileName; string fileContentType = file.ContentType; byte[] fileBytes = new byte[file.ContentLength]; var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength)); var personList = new List <Person>(); using (var package = new ExcelPackage(file.InputStream)) { var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; // rowIterator tells which row to start at for (int rowIterator = 1; rowIterator <= noOfRow; rowIterator++) { var person = new Person(); person.Name = workSheet.Cells[rowIterator, 1].Value.ToString(); personList.Add(person); } } foreach (var p in personList) { db.People.Add(p); } db.SaveChanges(); } return(RedirectToAction("Index")); } return(View()); }
public IHttpActionResult EditSchedulerEvent(int id, WebAPIRecurringEvent webAPIEvent) { var updatedSchedulerEvent = (SchedulerRecurringEvent)webAPIEvent; updatedSchedulerEvent.Id = id; db.Entry(updatedSchedulerEvent).State = EntityState.Modified; if (!string.IsNullOrEmpty(updatedSchedulerEvent.RecType) && updatedSchedulerEvent.RecType != "none") { //all modified occurrences must be deleted when we update a recurring series //https://docs.dhtmlx.com/scheduler/server_integration.html#savingrecurringevents db.SchedulerRecurringEvents.RemoveRange( db.SchedulerRecurringEvents.Where(e => e.EventPID == id) ); } db.SaveChanges(); return(Ok(new { action = "updated" })); }
public void Add(string newFIO) { if (check.Firmness(newFIO) && check.FIOvalidation(newFIO)) { try { Lector newRow = new Lector(newFIO); var equalRecords = LectorDB.Lectors.Where(l => l.FIO.Equals(newFIO)); if (equalRecords.Any()) { MessageBox.Show("Такой преподаватель уже существует в базе", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { LectorDB.Lectors.Add(newRow); LectorDB.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Произошла ошибка добавления\n" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void Add(string name, int year) { if (check.Firmness(name) && check.IntegerValidation(year)) { try { Group newRow = new Group(name, year); var equalRecords = GroupDB.Groups.Where(l => l.Name.Equals(name) && l.Year.Equals(year)); if (equalRecords.Any()) { MessageBox.Show("Такая учебная группа уже существует в базе", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { GroupDB.Groups.Add(newRow); GroupDB.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Произошла ошибка добавления\n" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public IActionResult Add(String name, String email) { SchedulerContext db = new SchedulerContext(); db.EmailRecipients.Add(new Entity.EmailRecipient() { RecipientId = Guid.NewGuid(), Name = name, Email = email }); db.SaveChanges(); return(Content("Added successfully")); }
public void Add(string newNumber) { if (check.Firmness(newNumber) && check.TexboxValidation(newNumber)) { try { Auditory newRow = new Auditory(newNumber); var equalRecords = DB.Auditories.Where(l => l.Number.Equals(newNumber)); if (equalRecords.Any()) { MessageBox.Show("Такая аудитория уже существует в базе", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DB.Auditories.Add(newRow); DB.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Произошла ошибка добавления\n" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public bool CreateChannel(ChannelDto channelDto, long userId) { try { var c = _context.Channel.Add(new Channel { channe_description = channelDto.Description, channel_name = channelDto.Name }); _context.SaveChanges(); if (!AddUserRole(c.channel_id, userId, 0)) { return(false); } } catch (DbUpdateException) { return(false); } return(true); }