コード例 #1
0
        public ActionResult Create([Bind(Include = "Image_Link,Title,Description,Congrats_Messages")] Kudo kudo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Wish newwish = new Wish();
                    newwish.KudoID  = kudo.KudoID;
                    newwish.Message = kudo.Congrats_Messages[0].Message;


                    db.Kudos.Add(kudo);
                    db.Wishes.Add(newwish);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException /*dex*/)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }


            return(View(kudo));
        }
コード例 #2
0
        public void Delete(string name)
        {
            var team = context.Teams.SingleOrDefault(p => p.Name == name);

            context.Teams.Remove(team);
            context.SaveChanges();
        }
コード例 #3
0
        public void SetBirthday(int employeeId, DateTime date)
        {
            var employee = context.Employees.Find(employeeId);

            if (employee == null)
            {
                throw new ArgumentException("Invalid Id");
            }

            employee.Birthday = date;
            context.SaveChanges();
        }
コード例 #4
0
 public ActionResult Create(Patient patient, int DoctorId)
 {
     _db.Patients.Add(patient);
     if (DoctorId != 0)
     {
         _db.DoctorPatientSpecialties.Add(new DoctorPatientSpecialty()
         {
             DoctorId = DoctorId, PatientId = patient.PatientId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #5
0
        public void InviteUser(string teamName, string username)
        {
            var team = context.Teams.SingleOrDefault(p => p.Name == teamName);
            var user = context.Users.SingleOrDefault(p => p.Username == username);

            var invitation = new Invitation
            {
                Team        = team,
                InvitedUser = user,
                IsActive    = true
            };

            context.Add(invitation);
            context.SaveChanges();
        }
        public void SetManager(int employeeId, int managerId)
        {
            var employee = GetEmployee(employeeId);
            var manager  = GetEmployee(managerId);

            employee.Manager = manager;
            db.SaveChanges();
        }
コード例 #7
0
        public void AddUser(string username, string password, string firstName, string lastName, int age, string genderString)
        {
            var gender = Enum.Parse <Gender>(genderString);

            var user = new User
            {
                Username  = username,
                Password  = password,
                FirstName = firstName,
                LastName  = lastName,
                Age       = age,
                Gender    = gender
            };

            context.Users.Add(user);
            context.SaveChanges();
        }
コード例 #8
0
        public virtual IActionResult Post(TDtoPost input)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var otr = _mapper.Map <TEntity>(input);

                    _dbSet.Add(otr);
                    _context.SaveChanges();
                    transaction.Commit();
                    return(Ok());
                }
                catch (Exception)
                {
                    return(BadRequest());
                }
            }
        }
コード例 #9
0
ファイル: ConferenceController.cs プロジェクト: wanaxe/Study
 public ActionResult JSONAdd(Conference conference)
 {
     IList<Conference> conferences = null;
     using (var context = new OfficeContext())
     {
         context.Conferences.Add(conference);
         context.SaveChanges();
         conferences = context.Conferences.ToList();
     }
     return conferences.GridJSONActions<Conference>();
 }
コード例 #10
0
ファイル: ConferenceController.cs プロジェクト: wanaxe/Study
        public ActionResult JSONAdd(Conference conference)
        {
            IList <Conference> conferences = null;

            using (var context = new OfficeContext())
            {
                context.Conferences.Add(conference);
                context.SaveChanges();
                conferences = context.Conferences.ToList();
            }
            return(conferences.GridJSONActions <Conference>());
        }
コード例 #11
0
        public void AddTeamTo(string eventName, string teamName)
        {
            var team      = context.Teams.SingleOrDefault(p => p.Name == teamName);
            var @event    = context.Events.Where(p => p.Name == eventName).OrderByDescending(p => p.StartDate).First();
            var teamEvent = new TeamEvent
            {
                Team  = team,
                Event = @event
            };

            context.TeamEvents.Add(teamEvent);
            context.SaveChanges();
        }
コード例 #12
0
        public IActionResult Post(Employee employee) //<= model Binding
                                                     //inseriemnto di un nuovo employee
        {
            using var _ctx = new OfficeContext();
            if (employee != null)
            {
                _ctx.Employees.Add(employee);
                _ctx.SaveChanges();

                return(Ok());
            }

            return(BadRequest("Invalid employee"));
        }
コード例 #13
0
        public void SetManager(int employeeId, int managerId)
        {
            var employee = this.context.Employees.Find(employeeId);

            var manager = this.context.Employees.Find(managerId);

            if (employee == null || manager == null)
            {
                throw new  ArgumentException("Invalid Id!");
            }

            employee.Manager = manager;
            context.SaveChanges();
        }
コード例 #14
0
        public IActionResult Put(int id, Employee employee)
        //modifica di un employee
        {
            using var _ctx = new OfficeContext();
            if (employee != null && id == employee.Id)
            {
                _ctx.Employees.Update(employee);
                _ctx.SaveChanges();


                return(Ok());
            }
            return(BadRequest("Error updating Employee"));
        }
コード例 #15
0
        public IActionResult Delete(int id) //cancella in base all'id

        {
            using var _ctx = new OfficeContext();
            var employee = _ctx.Employees.SingleOrDefault(e => e.Id == id);

            if (employee != null)
            {
                _ctx.Employees.Remove(employee);
                _ctx.SaveChanges();
                return(Ok());
            }
            else
            {
                return(BadRequest("Cannot delete Employee"));
            }
        }
コード例 #16
0
        public void CreateEvent(string name, string description, DateTime startDate, DateTime endDate,
                                string creatorName)
        {
            var creator = context.Users.SingleOrDefault(p => p.Username == creatorName);

            var @event = new Event
            {
                Name        = name,
                Description = description,
                StartDate   = startDate,
                EndDate     = endDate,
                Creator     = creator
            };


            context.Add(@event);
            context.SaveChanges();
        }
コード例 #17
0
        public ActionResult Schedule(Params args, Schedule scheduleObject)
        {
            scheduleObject.SetCurrentCultureInfo();
            ActionResult result       = null;
            var          parentID     = Guid.Parse(Session["ParentID"].ToString());
            var          scheduleType = (ScheduleType)int.Parse(Session["ScheduleType"].ToString());

            using (var context = new OfficeContext())
            {
                if (args.CurrentAction == "Save")
                {
                    var     startTime = DateTime.Parse(args.StartTime.Replace("上午", "AM").Replace("下午", "PM"));
                    var     endTime   = DateTime.Parse(args.EndTime.Replace("上午", "AM").Replace("下午", "PM"));
                    Seminar appoint   = new Seminar()
                    {
                        StartTime         = startTime,
                        EndTime           = endTime,
                        Subject           = args.Subject,
                        Location          = args.Location,
                        Description       = args.Description,
                        Owner             = args.Owner,
                        Priority          = args.Priority,
                        Recurrence        = args.Recurrence,
                        RecurrenceType    = args.RecurrenceType,
                        RecurrenceCount   = Convert.ToInt16(args.RecurrenceTypeCount),
                        Reminder          = args.Reminder,
                        Categorize        = args.Categorize,
                        AllDay            = args.AllDay,
                        RecurrenceEndDate = args.RecurrenceEnd != null?Convert.ToDateTime(args.RecurrenceEnd) : endTime,
                                                RecurrenceStartDate = args.RecurrenceStart != null?Convert.ToDateTime(args.RecurrenceStart) : startTime,
                                                                          RecurrenceRule = args.RecurrenceRules,
                                                                          ParentID       = parentID,
                                                                          ScheduleType   = scheduleType,
                                                                          CurrentUser    = User.Identity.Name
                    };
                    context.Seminars.Add(appoint);
                    context.SaveChanges();
                }
                else if (args.CurrentAction == "EditOccurrence")
                {
                    //SeminarRepository.EditOccurrence(args);
                }
                else if (args.CurrentAction == "Edit")
                {
                    var appid     = int.Parse(args.AppID);
                    var point     = context.Seminars.Single(s => s.Id == appid);
                    var startTime = DateTime.Parse(args.StartTime.Replace("上午", "AM").Replace("下午", "PM"));
                    var endTime   = DateTime.Parse(args.EndTime.Replace("上午", "AM").Replace("下午", "PM"));

                    point.StartTime         = startTime;
                    point.EndTime           = endTime;
                    point.Subject           = args.Subject;
                    point.Location          = args.Location;
                    point.Description       = args.Description;
                    point.Owner             = args.Owner;
                    point.Priority          = args.Priority;
                    point.Recurrence        = args.Recurrence;
                    point.RecurrenceType    = args.RecurrenceType;
                    point.RecurrenceCount   = Convert.ToInt16(args.RecurrenceTypeCount);
                    point.Reminder          = args.Reminder;
                    point.Categorize        = args.Categorize;
                    point.AllDay            = args.AllDay;
                    point.RecurrenceEndDate = args.RecurrenceEnd != null?Convert.ToDateTime(args.RecurrenceEnd) : endTime;

                    point.RecurrenceStartDate = args.RecurrenceStart != null?Convert.ToDateTime(args.RecurrenceStart) : startTime;

                    point.RecurrenceRule = args.RecurrenceRules;
                    point.ParentID       = parentID;
                    point.ScheduleType   = scheduleType;
                    point.CurrentUser    = User.Identity.Name;
                    //context.Seminars.Add(point);
                    context.SaveChanges();
                }
                else if (args.CurrentAction == "Delete")
                {
                    var appid = int.Parse(args.AppID);
                    var point = context.Seminars.Single(s => s.Id == appid);
                    context.Seminars.Remove(point);
                    context.SaveChanges();
                }
                else if (args.CurrentAction == "DismissAll" || args.CurrentAction == "Dismiss" || args.CurrentAction == "Snooze")
                {
                    //SeminarRepository.ReminderAction(args);
                }

                result = context.Seminars.Where(s => s.ParentID == parentID && s.ScheduleType == (ScheduleType)scheduleType).ToList().ScheduleActions <ScheduleHtmlActionResult>();
            }

            return(result);
        }
コード例 #18
0
 public ActionResult Create(Doctor doctor)
 {
     _db.Doctors.Add(doctor);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #19
0
        public static void Initialize(OfficeContext context)
        {
            context.Database.EnsureCreated();
            if (context.Services.Any())
            {
                return; // BD a fost creata anterior
            }
            var services = new Service[]
            {
                new Service {
                    Title = "Baltagul", Description = "Mihail Sadove1anu", Price = Decimal.Parse("22")
                },
                new Service {
                    Title = "Baltul", Description = "Mihal Sadoveanu", Price = Decimal.Parse("2")
                },
                new Service {
                    Title = "Baltaul", Description = "Mihil Sadoveanu", Price = Decimal.Parse("12")
                },
            };

            foreach (Service s in services)
            {
                context.Services.Add(s);
            }
            context.SaveChanges();
            var customers = new Customer[]
            {
                new Customer {
                    CustomerID = 1050, Name = "Popescu Marcela", BirthDate = DateTime.Parse("1979-09-01")
                },
                new Customer {
                    CustomerID = 1045, Name = "Mihailescu Cornel", BirthDate = DateTime.Parse("1969-07-08")
                },
            };

            foreach (Customer c in customers)
            {
                context.Customers.Add(c);
            }
            context.SaveChanges();
            var appointments = new Appointment[]
            {
                new Appointment {
                    ServiceID = 2, CustomerID = 1050
                },
                new Appointment {
                    ServiceID = 3, CustomerID = 1045
                },
                new Appointment {
                    ServiceID = 4, CustomerID = 1045
                },
                new Appointment {
                    ServiceID = 2, CustomerID = 1050
                },
            };


            foreach (Appointment e in appointments)
            {
                context.Appointments.Add(e);
            }

            var doctors = new Doctor[]
            {
                new Doctor {
                    DoctorName = "Humanitas", Specializare = "Str. Aviatorilor, nr. 40,Bucuresti"
                },
            };

            foreach (Doctor p in doctors)
            {
                context.Doctors.Add(p);
            }
            context.SaveChanges();

            var doctorservicess = new DoctorService[]
            {
                new DoctorService {
                    ServiceID = services.Single(c => c.Title == "Baltaul").ID,
                    DoctorID  = doctors.Single(i => i.DoctorName == "Humanitas").ID
                },
            };

            foreach (DoctorService pb in doctorservicess)
            {
                context.DoctorServices.Add(pb);
            }
            context.SaveChanges();
        }
コード例 #20
0
ファイル: ScheduleController.cs プロジェクト: wanaxe/Study
        public ActionResult Schedule(Params args, Schedule scheduleObject)
        {
            scheduleObject.SetCurrentCultureInfo();
            ActionResult result = null;
            var parentID = Guid.Parse(Session["ParentID"].ToString());
            var scheduleType = (ScheduleType)int.Parse(Session["ScheduleType"].ToString());
            using (var context = new OfficeContext())
            {
                if (args.CurrentAction == "Save")
                {
                    var startTime = DateTime.Parse(args.StartTime.Replace("上午", "AM").Replace("下午", "PM"));
                    var endTime = DateTime.Parse(args.EndTime.Replace("上午", "AM").Replace("下午", "PM"));
                    Seminar appoint = new Seminar()
                    {
                        StartTime = startTime,
                        EndTime = endTime,
                        Subject = args.Subject,
                        Location = args.Location,
                        Description = args.Description,
                        Owner = args.Owner,
                        Priority = args.Priority,
                        Recurrence = args.Recurrence,
                        RecurrenceType = args.RecurrenceType,
                        RecurrenceCount = Convert.ToInt16(args.RecurrenceTypeCount),
                        Reminder = args.Reminder,
                        Categorize = args.Categorize,
                        AllDay = args.AllDay,
                        RecurrenceEndDate = args.RecurrenceEnd != null ? Convert.ToDateTime(args.RecurrenceEnd) : endTime,
                        RecurrenceStartDate = args.RecurrenceStart != null ? Convert.ToDateTime(args.RecurrenceStart) : startTime,
                        RecurrenceRule = args.RecurrenceRules,
                        ParentID = parentID,
                        ScheduleType = scheduleType,
                        CurrentUser = User.Identity.Name
                    };
                    context.Seminars.Add(appoint);
                    context.SaveChanges();
                }
                else if (args.CurrentAction == "EditOccurrence")
                {
                    //SeminarRepository.EditOccurrence(args);
                }
                else if (args.CurrentAction == "Edit")
                {
                    var appid = int.Parse(args.AppID);
                    var point = context.Seminars.Single(s => s.Id == appid);
                    var startTime = DateTime.Parse(args.StartTime.Replace("上午", "AM").Replace("下午", "PM"));
                    var endTime = DateTime.Parse(args.EndTime.Replace("上午", "AM").Replace("下午", "PM"));

                    point.StartTime = startTime;
                    point.EndTime = endTime;
                    point.Subject = args.Subject;
                    point.Location = args.Location;
                    point.Description = args.Description;
                    point.Owner = args.Owner;
                    point.Priority = args.Priority;
                    point.Recurrence = args.Recurrence;
                    point.RecurrenceType = args.RecurrenceType;
                    point.RecurrenceCount = Convert.ToInt16(args.RecurrenceTypeCount);
                    point.Reminder = args.Reminder;
                    point.Categorize = args.Categorize;
                    point.AllDay = args.AllDay;
                    point.RecurrenceEndDate = args.RecurrenceEnd != null ? Convert.ToDateTime(args.RecurrenceEnd) : endTime;
                    point.RecurrenceStartDate = args.RecurrenceStart != null ? Convert.ToDateTime(args.RecurrenceStart) : startTime;
                    point.RecurrenceRule = args.RecurrenceRules;
                    point.ParentID = parentID;
                    point.ScheduleType = scheduleType;
                    point.CurrentUser = User.Identity.Name;
                    //context.Seminars.Add(point);
                    context.SaveChanges();
                }
                else if (args.CurrentAction == "Delete")
                {
                    var appid = int.Parse(args.AppID);
                    var point = context.Seminars.Single(s => s.Id == appid);
                    context.Seminars.Remove(point);
                    context.SaveChanges();
                }
                else if (args.CurrentAction == "DismissAll" || args.CurrentAction == "Dismiss" || args.CurrentAction == "Snooze")
                {
                    //SeminarRepository.ReminderAction(args);
                }

                result = context.Seminars.Where(s => s.ParentID == parentID && s.ScheduleType == (ScheduleType)scheduleType).ToList().ScheduleActions<ScheduleHtmlActionResult>();
            }

            return result;
        }
コード例 #21
0
ファイル: HomeController.cs プロジェクト: ltvch/SimpleCore
 public ActionResult SeatPupUp(Seat seat)
 {
     db.Seats.Add(seat);                // добавляем в бд
     db.SaveChanges();                  //сохраняем в бд все изменения
     return(RedirectToAction("Index")); //возвращаемся на основное окно
 }
コード例 #22
0
 private static void AddUser(User user)
 {
     context.Users.Add(user);
     context.SaveChanges();
 }