コード例 #1
0
ファイル: CompanyDAO.cs プロジェクト: eoinr393/CompanyAPI
        /// <summary>
        /// Create a Company
        /// </summary>
        /// <param name="company"></param>
        /// <returns>The Created Company</returns>
        public async Task <Models.Company> CreateCompany(Models.Company company)
        {
            await dbContext.Companys.AddAsync(company);

            dbContext.SaveChanges();
            return(await this.GetCompanyByISIN(company.ISIN));
        }
コード例 #2
0
        public IActionResult Create(CreateModel Emp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (Emp == null || Emp.Employee == null || string.IsNullOrEmpty(Emp.Employee.LastName))
            {
                return(NotFound());
            }
            int checkExist = (from e in companyDB.Employees
                              where e.LastName == Emp.Employee.LastName && e.FirstName == Emp.Employee.FirstName
                              select e).Count();

            if (0 < checkExist)
            {
                return(BadRequest());
            }
            if (Emp.DepartmentName != null)
            {
                Emp.Employee.DepartmentId = companyDB.GetDepartmentIdByName(Emp.DepartmentName);
            }
            companyDB.Employees.Add(Emp.Employee);
            companyDB.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "Name,Email,Password")] CompanyViewModel companyVM)
        {
            if (ModelState.IsValid)
            {
                Company company = new Company();

                if (!company.UniqueEmail(companyVM.Email))
                {
                    ViewBag.Verify = "This email already exists!";

                    return(View(companyVM));
                }
                company.Name     = companyVM.Name;
                company.Email    = companyVM.Email;
                company.Password = BCrypt.Net.BCrypt.HashPassword(companyVM.Password);



                db.Companies.Add(company);
                db.SaveChanges();
                return(RedirectToAction("Login"));
            }

            return(View(companyVM));
        }
コード例 #4
0
        public Employee CreateEmployee(string firstName, string lastName, string email, decimal salary = 0)
        {
            var employee = Employee.Create(firstName, lastName, email, salary);

            context.Employees.Add(employee);
            context.SaveChanges();

            return(employee);
        }
コード例 #5
0
        public Department CreateDepartment(string name, string description = "")
        {
            var department = Department.Create(name, description);

            context.Departments.Add(department);
            context.SaveChanges();

            return(department);
        }
コード例 #6
0
        public ActionResult Create([Bind(Include = "CompanyId,Name,Ticker,Asset,Debt,Liquidity,Assessment")] Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(company));
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "ID,Name,Description")] Reclamo reclamo)
        {
            if (ModelState.IsValid)
            {
                db.Reclamos.Add(reclamo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(reclamo));
        }
コード例 #8
0
        public ActionResult Create([Bind(Include = "ID,Name,Age")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
コード例 #9
0
        public ActionResult Create([Bind(Include = "ID,Name,Email,Phone,BookingTime,ServiceID")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                db.Bookings.Add(booking);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ServiceID = new SelectList(db.Services, "ID", "Title", booking.ServiceID);
            return(View(booking));
        }
コード例 #10
0
ファイル: TickerDAO.cs プロジェクト: eoinr393/CompanyAPI
        /// <summary>
        /// Creates a Ticker
        /// </summary>
        /// <param name="ticker">the ticker to be created</param>
        /// <returns>the ticker</returns>
        public async Task <Ticker> CreateTicker(Ticker ticker)
        {
            //If ticker already exists return that ticker as ticker names are unique
            var existing = await this.GetTickerByName(ticker.Name);

            if (existing != null)
            {
                return(existing);
            }

            await dbContext.Tickers.AddAsync(ticker);

            dbContext.SaveChanges();
            return(await this.GetTickerByName(ticker.Name));
        }
コード例 #11
0
        /// <summary>
        /// Creates a new entry in the company_exchange table
        /// </summary>
        /// <param name="companyExchange">the to-be-created company</param>
        /// <returns>the created object</returns>
        public async Task <CompanyExchange> CreateCompanyExchange(CompanyExchange companyExchange)
        {
            await dbContext.CompanyExchange.AddAsync(companyExchange);

            dbContext.SaveChanges();
            return(companyExchange);
        }
コード例 #12
0
        public void PostBrand(Brand newBrand)
        {
            CompanyDBContext db = new CompanyDBContext();

            db.Brands.Add(newBrand);
            db.SaveChanges();
        }
コード例 #13
0
 public void RemoveEntity <T>(T Entity) where T : class
 {
     using (var CompanyDBContext = new CompanyDBContext())
     {
         CompanyDBContext.Set <T>().Remove(Entity);
         CompanyDBContext.SaveChanges();
     }
 }
コード例 #14
0
        public void PutBrand(Brand brandData)
        {
            CompanyDBContext db = new CompanyDBContext();
            var existingBrand   = db.Brands.Where(temp => temp.BrandID == brandData.BrandID).FirstOrDefault();

            existingBrand.BrandName = brandData.BrandName;
            db.SaveChanges();
        }
コード例 #15
0
        public void DeleteBrand(long BrandID)
        {
            CompanyDBContext db = new CompanyDBContext();
            var existingBrand   = db.Brands.Where(temp => temp.BrandID == BrandID).FirstOrDefault();

            db.Brands.Remove(existingBrand);
            db.SaveChanges();
        }
コード例 #16
0
        public ActionResult Create(Product product)

        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                List <Category> categories = db.Categories.ToList();
                ViewBag.Cat = categories;
                List <Brand> brands = db.Brands.ToList();
                ViewBag.Brand = brands;
                return(View());
            }
        }
コード例 #17
0
 public void UpdateOrder(Order Entity)
 {
     using (var CompanyDBContext = new CompanyDBContext())
     {
         var OldEntity = CompanyDBContext.Set <Order>().Find(Entity.Id);
         OldEntity.Name = Entity.Name;
         CompanyDBContext.SaveChanges();
     }
 }
コード例 #18
0
        public IActionResult Create(DepartmentModel dep)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (dep == null || dep.department == null || string.IsNullOrEmpty(dep.department.Name))
            {
                return(NotFound());
            }
            int checkExist = (from e in companyDB.Departments
                              where e.Name == dep.department.Name
                              select e).Count();

            if (0 < checkExist)
            {
                return(BadRequest());
            }
            companyDB.Departments.Add(dep.department);
            companyDB.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #19
0
 public void UpdateWorker(Worker Entity)
 {
     using (var CompanyDBContext = new CompanyDBContext())
     {
         var OldEntity = CompanyDBContext.Set <Worker>().Find(Entity.Id);
         OldEntity.Name         = Entity.Name;
         OldEntity.Surname      = Entity.Surname;
         OldEntity.Middlename   = Entity.Middlename;
         OldEntity.DepartmentId = Entity.Department.Id;
         OldEntity.Birthday     = Entity.Birthday;
         OldEntity.GenderId     = Entity.Gender.Id;
         CompanyDBContext.SaveChanges();
     }
 }
コード例 #20
0
        public ActionResult Create([Bind(Include = "ID,Title,Description,Duration,Spaces,Price,Rating,Availability")] ServiceViewModel serviceVM)
        {
            if (ModelState.IsValid)
            {
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <ServiceViewModel, Service>();
                });

                IMapper mapper  = config.CreateMapper();
                Service service = mapper.Map <ServiceViewModel, Service>(serviceVM);

                string userId = Session["User"].ToString();
                service.CompanyID = Convert.ToInt32(userId);

                db.Services.Add(service);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //ViewBag.CompanyID = new SelectList(db.Companies, "ID", "Name", service.CompanyID);
            return(View(serviceVM));
        }
コード例 #21
0
 public ActionResult Create([Bind(Include = "ProductID, ProductName, Price, DOP, AvailabilityStatus, CategoryID, BrandID, Active, Photo")] Product p)
 {
     if (ModelState.IsValid)
     {
         if (Request.Files.Count >= 1)
         {
             var file     = Request.Files[0];
             var imgBytes = new Byte[file.ContentLength];
             file.InputStream.Read(imgBytes, 0, file.ContentLength);
             var base64String = Convert.ToBase64String(imgBytes, 0, imgBytes.Length);
             p.Photo = base64String;
         }
         db.Products.Add(p);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         ViewBag.Categories = db.Categories.ToList();
         ViewBag.Brands     = db.Brands.ToList();
         return(View());
     }
 }
コード例 #22
0
 public ActionResult AddPhoto(Photo ph, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         if (file != null)
         {
             file.SaveAs(HttpContext.Server.MapPath("~/Content/Photos/")
                         + file.FileName);
             ph.URL = file.FileName;
         }
         db.Photos.Add(ph);
         db.SaveChanges();
     }
     return(RedirectToAction("Index", "Photo"));
 }
コード例 #23
0
        /// <summary>
        /// Creates a new Exchange
        /// </summary>
        /// <param name="exchange">The new exchange to be created</param>
        /// <returns>the newly create</returns>
        public async Task <Exchange> CreateExchange(Exchange exchange)
        {
            //if exchange already exists just return that exchange as exchange names are unique
            var existingExchange = await this.GetExchangeByName(exchange.Name);

            if (existingExchange != null)
            {
                return(existingExchange);
            }

            await dbContext.Exchange.AddAsync(exchange);

            dbContext.SaveChanges();
            return(await this.GetExchangeByName(exchange.Name));
        }
コード例 #24
0
        public void UpdateDepartment(Department Entity)
        {
            using (var CompanyDBContext = new CompanyDBContext())
            {
                var OldEntity = CompanyDBContext.Set <Department>().Find(Entity.Id);

                OldEntity.Name = Entity.Name;

                if (Entity.Boss != null)
                {
                    OldEntity.BossId = Entity.Boss.Id;
                }
                else
                {
                    OldEntity.BossId = null;
                }

                CompanyDBContext.SaveChanges();
            }
        }
コード例 #25
0
        public void SetUp()
        {
            // Insert seed data into the database using one instance of the context
            using (var context = new CompanyDBContext(options))
            {
                context.Database.EnsureDeleted();

                context.CompanyExchange.Add(new Models.CompanyExchange {
                    CompanyId = 1, ExchangeId = 1
                });
                context.CompanyExchange.Add(new Models.CompanyExchange {
                    CompanyId = 1, ExchangeId = 2
                });
                context.CompanyExchange.Add(new Models.CompanyExchange {
                    CompanyId = 2, ExchangeId = 3
                });
                context.CompanyExchange.Add(new Models.CompanyExchange {
                    CompanyId = 2, ExchangeId = 4
                });
                context.CompanyExchange.Add(new Models.CompanyExchange {
                    CompanyId = 2, ExchangeId = 5
                });
                context.CompanyExchange.Add(new Models.CompanyExchange {
                    CompanyId = 3, ExchangeId = 2
                });
                context.CompanyExchange.Add(new Models.CompanyExchange {
                    CompanyId = 3, ExchangeId = 3
                });
                context.CompanyExchange.Add(new Models.CompanyExchange {
                    CompanyId = 3, ExchangeId = 4
                });

                context.SaveChanges();
            }

            dao = new CompanyExchangeDAO(new CompanyDBContext(options));
        }
コード例 #26
0
ファイル: TickerDAOTest.cs プロジェクト: eoinr393/CompanyAPI
        public void SetUp()
        {
            // Insert seed data into the database using one instance of the context
            using (var context = new CompanyDBContext(options))
            {
                context.Database.EnsureDeleted();

                context.Tickers.Add(new Ticker {
                    CompanyId = 1, Name = "AAA"
                });
                context.Tickers.Add(new Ticker {
                    CompanyId = 1, Name = "GME"
                });
                context.Tickers.Add(new Ticker {
                    CompanyId = 2, Name = "GOOGL"
                });
                context.Tickers.Add(new Ticker {
                    CompanyId = 2, Name = "GOOG"
                });
                context.Tickers.Add(new Ticker {
                    CompanyId = 2, Name = "NFLX"
                });
                context.Tickers.Add(new Ticker {
                    CompanyId = 3, Name = "G"
                });
                context.Tickers.Add(new Ticker {
                    CompanyId = 3, Name = "D"
                });
                context.Tickers.Add(new Ticker {
                    CompanyId = 3, Name = "AAPL"
                });

                context.SaveChanges();
            }

            dao = new TickerDAO(new CompanyDBContext(options));
        }
コード例 #27
0
        public void SetUp()
        {
            // Insert seed data into the database using one instance of the context
            using (var context = new CompanyDBContext(options))
            {
                context.Database.EnsureDeleted();

                context.Exchange.Add(new Exchange {
                    Name = "New York Stock Exchange"
                });
                context.Exchange.Add(new Exchange {
                    Name = "Nasdaq"
                });
                context.Exchange.Add(new Exchange {
                    Name = "Japan Exchange Group"
                });
                context.Exchange.Add(new Exchange {
                    Name = "London Stock Exchange"
                });
                context.Exchange.Add(new Exchange {
                    Name = "Shanghai Stock Exchange"
                });
                context.Exchange.Add(new Exchange {
                    Name = "Hong Kong Stock Exchange"
                });
                context.Exchange.Add(new Exchange {
                    Name = "Euronext"
                });
                context.Exchange.Add(new Exchange {
                    Name = "Toronto Stock Exchange"
                });

                context.SaveChanges();
            }

            dao = new ExchangeDAO(new CompanyDBContext(options));
        }
コード例 #28
0
ファイル: CompanyDAOTest.cs プロジェクト: eoinr393/CompanyAPI
        public void Setup()
        {
            // Insert seed data into the database using one instance of the context
            using (var context = new CompanyDBContext(options))
            {
                context.Database.EnsureDeleted();

                context.Companys.Add(new Models.Company {
                    Id = 1, Name = "Company1", ISIN = "ER00001", Website = "test1.com"
                });
                context.Companys.Add(new Models.Company {
                    Id = 2, Name = "Company2", ISIN = "ER00002", Website = "test2.com"
                });
                context.Companys.Add(new Models.Company {
                    Id = 3, Name = "Company3", ISIN = "ER00003", Website = "test3.com"
                });
                context.Companys.Add(new Models.Company {
                    Id = 4, Name = "Company4", ISIN = "ER00004", Website = "test4.com"
                });
                context.SaveChanges();
            }

            dao = new CompanyDAO(new CompanyDBContext(options));
        }
コード例 #29
0
 public void AddEmp(Employees obj)
 {
     _context.Add(obj);
     _context.SaveChanges();
 }