コード例 #1
0
ファイル: BaseRepository.cs プロジェクト: 7net-nl/WebService
        public virtual string Add(TEntity entity)
        {
            Result = context.Set <TEntity>().Add(entity).State.ToString();
            context.SaveChanges();

            return(Result);
        }
コード例 #2
0
        public void AddEquipment(EquipmentModel equipmentModel)
        {
            var equipment = factoryContext.Equipment.Where(eq => eq.Title == equipmentModel.Title).ToList();

            if (equipment.Count == 0)
            {
                factoryContext.Equipment.Add(new Equipment()
                {
                    Title = equipmentModel.Title
                });

                factoryContext.RoomEquipment.Add(new RoomEquipment()
                {
                    RoomId          = (int)equipmentModel.RoomId,
                    EquipmentId     = equipmentModel.Id,
                    EquipmentNumber = equipmentModel.Number
                });
            }
            else
            {
                var equipmentForRoom = factoryContext.RoomEquipment.Find(equipmentModel.RoomId, equipment[0].Id);
                equipmentForRoom.EquipmentNumber            += equipmentModel.Number;
                factoryContext.Entry(equipmentForRoom).State = EntityState.Modified;
            }

            factoryContext.SaveChanges();
        }
コード例 #3
0
 public ActionResult Create(Machine machine, string StatusTypes)
 {
     machine.Status = StatusTypes;
     _db.Machines.Add(machine);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #4
0
 public ActionResult Create(Engineer newEngineer)
 {
     newEngineer.FullName = newEngineer.FirstName + " " + newEngineer.LastName;
     _db.Engineers.Add(newEngineer);
     _db.SaveChanges();
     return(RedirectToAction("Details", new { id = newEngineer.EngineerId }));
 }
コード例 #5
0
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    var    fileName = Path.GetFileName(file.FileName);
                    string path2    = Path.GetRandomFileName();
                    fileName = path2 + fileName;
                    var path = Path.Combine(Server.MapPath("~/Upload/"), fileName);

                    product.Photo = fileName;

                    file.SaveAs(path);//saved the file
                }



                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId = new SelectList(db.Cities, "Id", "Name", product.CityId);
            return(View(product));
        }
コード例 #6
0
        // PUT api/Service/5
        public HttpResponseMessage PutCity(int id, City city)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != city.Id)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
コード例 #7
0
 public ActionResult Create(Engineer engineer)
 {
     if (!_db.Engineers.Any(x => x.EngineerName == engineer.EngineerName))
     {
         _db.Engineers.Add(engineer);
         _db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
コード例 #8
0
 public ActionResult Create(Machine machine)
 {
     if (!_db.Machines.Any(x => x.MachineName == machine.MachineName))
     {
         _db.Machines.Add(machine);
         _db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
コード例 #9
0
 public ActionResult Create(Machine machine)
 {
     if (machine.DateInstalled.Year == 0001)
     {
         machine.DateInstalled = DateTime.Now;
     }
     _db.Machines.Add(machine);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #10
0
 [HttpPost]                                  //Actually creates the machine that was just entered
 public ActionResult Create(Machine machine) //int EngineerId
 {
     _db.Machines.Add(machine);              //adds the new machine to the machine database
     // if (EngineerId != 0) //Basically means: if an engineer was selected in the form add it to the join table as well??
     // {
     //     _db.EngineerMachine.Add(new EngineerMachine() { EngineerId = EngineerId, MachineId = machine.MachineId });
     // }
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #11
0
        public async Task <ActionResult> Create(Machine Machine)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            Machine.User = currentUser;
            _db.Machines.Add(Machine);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #12
0
        public async Task <ActionResult> Create(Incident Incident, int EngineerId, int MachineId)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            Incident.User = currentUser;
            _db.Incidents.Add(Incident);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #13
0
        public ActionResult Create(City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(city));
        }
コード例 #14
0
        public ActionResult Create(Engineer engineer)
        {
            if (engineer.DateHired.Year == 0001)
            {
                engineer.DateHired = DateTime.Now;
            }

            _db.Engineers.Add(engineer);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #15
0
        public ActionResult Create([Bind(Include = "FactoryId,FactoryName")] Factory factory)
        {
            if (ModelState.IsValid)
            {
                db.Factories.Add(factory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(factory));
        }
コード例 #16
0
 public ActionResult Create(Machine machine)
 {
     // var duplicateCheck = _db.MachineEngineer.FirstOrDefault(join=>join.MachineId==MachineId && join.EngineerId==engineer.EngineerId);
     // if (duplicateCheck != null)
     // {
     // return RedirectToAction("Details", new {id=engineer.EngineerId});
     // }
     _db.Machines.Add(machine);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #17
0
 public ActionResult Create(Engineer engineer)
 {
     if (ModelState.IsValid)
     {
         DateTime now = DateTime.Now;
         engineer.HireDate = now;
         _db.Engineers.Add(engineer);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(engineer));
 }
コード例 #18
0
 public ActionResult Create(Machine machine)
 {
     if (ModelState.IsValid)
     {
         DateTime now = DateTime.Now;
         machine.InstallationDate = now;
         _db.Machines.Add(machine);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(machine));
 }
コード例 #19
0
        public async Task <ActionResult> Create(Engineer engineer)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            engineer.User = currentUser; //"STAMP" USER ON THE OBJECT
            _db.Engineers.Add(engineer);
            _db.SaveChanges();
            // _db.Engineers.Add(Engineer);
            // _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #20
0
 public ActionResult Create(Engineer engineer, int MachineId)
 {
     _db.Engineers.Add(engineer);
     if (MachineId != 0)
     {
         _db.MachineEngineer.Add(new MachineEngineer()
         {
             MachineId = MachineId, EngineerId = engineer.EngineerId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #21
0
 public ActionResult Create(Machine machine, int EngineerId)
 {
     _db.Machines.Add(machine);
     if (EngineerId != 0)
     {
         _db.EngineerMachine.Add(new EngineerMachine()
         {
             EngineerId = EngineerId, MachineId = machine.MachineId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #22
0
 public ActionResult Create(MachineType machineType, int LicenseId)
 {
     _db.MachineTypes.Add(machineType);
     if (LicenseId != 0)
     {
         _db.LicenseType.Add(new LicenseType()
         {
             MachineTypeId = machineType.MachineTypeId, LicenseId = LicenseId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Details", null, new { id = machineType.MachineTypeId }));
 }
コード例 #23
0
 public ActionResult Edit(Machine machine, int EngineerId)
 {
     if (EngineerId != 0)
     {
         _db.EngineerMachine.Add(new EngineerMachine()
         {
             EngineerId = EngineerId, MachineId = machine.MachineId
         });
     }
     _db.Entry(machine).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #24
0
 public ActionResult Create(Engineer engineer)
 {
     foreach (Engineer eng in _db.Engineers)
     {
         if (eng.FirstName == engineer.FirstName && eng.LastName == engineer.LastName)
         {
             return(RedirectToAction("Index"));
         }
     }
     _db.Engineers.Add(engineer);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #25
0
 public ActionResult Create(Engineer engineer, int LicenseId)
 {
     _db.Engineers.Add(engineer);
     if (LicenseId != 0)
     {
         _db.EngineerLicense.Add(new EngineerLicense()
         {
             EngineerId = engineer.EngineerId, LicenseId = LicenseId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Details", null, new { id = engineer.EngineerId }));
 }
コード例 #26
0
 public ActionResult Create(Machine machine, int LicenseId)
 {
     _db.Machines.Add(machine);
     if (LicenseId != 0)
     {
         _db.MachineLicense.Add(new MachineLicense()
         {
             LicenseId = LicenseId, MachineId = machine.MachineId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #27
0
 public ActionResult Create(Engineer engineer, int LicenseId)
 {
     _db.Engineers.Add(engineer);
     if (LicenseId != 0)
     {
         _db.LicenseEngineer.Add(new LicenseEngineer()
         {
             LicenseId = LicenseId, EngineerId = engineer.EngineerId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #28
0
        public ActionResult Create([Bind(Include = "EmployerId,FirstName,LastName,PhoneNumber,FactoryId")] Employer employer)
        {
            if (ModelState.IsValid)
            {
                var        listOfFactories = db.Factories.ToList();
                SelectList list            = new SelectList(listOfFactories, "FactoryId", "FactoryName");
                ViewBag.FactoryListName = list;
                db.Employers.Add(employer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employer));
        }
コード例 #29
0
 private void RegisterButton_Click(object sender, EventArgs e)
 {
     if (passwordEdit.Text != confirmEdit.Text)
     {
         MessageBox.Show("Ошибка при повторном вводе пароля");
         return;
     }
     else if (!CheckPassword(passwordEdit.Text))
     {
         MessageBox.Show("Пароль должен...");
         return;
     }
     using (var context = new FactoryContext())
     {
         try
         {
             var user = new User
             {
                 Login    = loginEdit.Text,
                 Password = passwordEdit.Text,
                 RoleId   = (int)User.UserRole.Customer,
                 Name     = nameEdit.Text
             };
             context.Users.Add(user);
             context.SaveChanges();
             MessageBox.Show("Вы успешно зарегистрированы и можете войти в систему");
             Back();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
コード例 #30
0
        public async Task <ActionResult> Create(Treat treat, int FlavorId)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            treat.User = currentUser;
            _db.Treats.Add(treat);
            if (FlavorId != 0)
            {
                _db.FlavorTreat.Add(new FlavorTreat()
                {
                    FlavorId = FlavorId, TreatId = treat.TreatId
                });
            }
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }