예제 #1
0
        public IHttpActionResult Put(int id, DGeometry dGeometry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dGeometry.deviation_id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DGeometryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public IHttpActionResult Put(int id, ELathe eLathe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eLathe.lathe_id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ELatheExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult Put(int id, BDescription bDescription)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bDescription.billet_id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BDescriptionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult Put(int id, ETransitionBaseTolerance eTransitionBaseTolerance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eTransitionBaseTolerance.base_requirement_id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ETransitionBaseToleranceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #5
0
        public IHttpActionResult Put(int id, ETransitionGeometryInput eTransitionGeometryInput)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eTransitionGeometryInput.transition_id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ETransitionGeometryInputExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult Put(int id, SurfaceCatalog surfaceCatalog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != surfaceCatalog.surface_code)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SurfaceCatalogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #7
0
        public void CreateNewUser(Role role,
                                  Company company,
                                  string first_name,
                                  string second_name,
                                  string patronymic,
                                  string login,
                                  string password)
        {
            string hashedPassword = this.HashPassword(password);

            Employee foundUser = null;

            using (MachineDbContext context = new MachineDbContext())
            {
                foundUser = context.Employees.FirstOrDefault(x => x.login.Equals(login));
                if (!(foundUser is null))
                {
                    throw new Exception("Пользователь с таким логином существует");
                }

                Employee newUser = new Employee()
                {
                    Role        = role,
                    Company     = company,
                    first_name  = first_name,
                    second_name = second_name,
                    patronymic  = patronymic,
                    login       = login,
                    password    = password
                };

                context.Employees.Add(newUser);
                context.SaveChanges();
            }
        }
예제 #8
0
 // GET: Machines
 public ActionResult Add(Company company)
 {
     using (var db = new MachineDbContext())
     {
         db.Companies.Add(company);
         db.SaveChanges();
         return(Json(new { nane = "Alessandro" }));
     }
 }
예제 #9
0
        public void AddRecord(Record r)
        {
            // List<Record> records;

            using (MachineDbContext context = new MachineDbContext())
            {
                if (!context.Records.Contains(r))
                {
                    context.Records.Add(r);
                    context.SaveChanges();
                }
            }
        }
예제 #10
0
        public void FillDatabase(string[] args)
        {
            List <Record> records = new List <Record>();

            foreach (string line in args)
            {
                string[] lines  = line.Split(new[] { ';', ',' });
                Record   record = this.ParseRecordString(lines);
                records.Add(record);
            }

            using (MachineDbContext context = new MachineDbContext())
            {
                context.Records.AddRange(records);
                context.SaveChanges();
            }
        }
예제 #11
0
        public void Test_CreateUser()
        {
            AutorizationService service = new AutorizationService();
            string login = "******";
            //string password = "******";

            Role adminRole = new Role()
            {
                name           = "admin",
                canEdit        = true,
                canEditCatalog = true,
                canGetData     = true,
                canEnter       = true,
            };

            using (MachineDbContext context = new MachineDbContext())
            {
                foreach (var employee in context.Employees)
                {
                    context.Employees.Remove(employee);
                }

                if (!(context.Roles.FirstOrDefault(x => x.name.Equals(adminRole.name)) is null))
                {
                    context.Roles.Add(adminRole);
                }

                context.SaveChanges();
            }

            //service.CreateNewUser(login, password, adminRole);

            using (MachineDbContext context = new MachineDbContext())
            {
                Assert.NotNull(context.Employees.FirstOrDefault(x => x.login.Equals(login)));
            }
        }