public async Task <IActionResult> PutPeopleModel(Guid id, PeopleModel peopleModel)
        {
            if (id != peopleModel.Id)
            {
                return(BadRequest());
            }

            _context.Entry(peopleModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PeopleModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <UserDb> AddUser(UserDb user)
        {
            user.Id = 0;
            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("MemberID,MemberName,InductionDate,Age")] Member member)
        {
            if (ModelState.IsValid)
            {
                _context.Add(member);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(member));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("Inv_ID,Inv_des,Inv_amount,Inv_date")] Invoice invoice)
        {
            if (ModelState.IsValid)
            {
                _context.Add(invoice);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(invoice));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] AspNetUser aspNetUser)
        {
            if (ModelState.IsValid)
            {
                db.Entry(aspNetUser).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(aspNetUser));
        }
        public async Task <ActionResult> Create([Bind(Include = "ForemanID,FirstName,LastName,Cell")] Foreman foreman)
        {
            if (ModelState.IsValid)
            {
                db.Foremen.Add(foreman);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(foreman));
        }
Beispiel #7
0
        public async Task <ActionResult> Create([Bind(Include = "PurchaserID,Name")] Purchaser purchaser)
        {
            if (ModelState.IsValid)
            {
                db.Purchasers.Add(purchaser);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(purchaser));
        }
Beispiel #8
0
        public async Task <IActionResult> Create([Bind("Emp_ID,Emp_lname,Emp_fname,Emp_phone,Emp_email,Cus_ID")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Cus_ID"] = new SelectList(_context.Customers, "Cus_ID", "Cus_ID", employee.Cus_ID);
            return(View(employee));
        }
Beispiel #9
0
        public async Task <IActionResult> Create([Bind("Cus_ID,Cus_lname,Cus_fname,Cus_phone,Cus_email,Cus_street,Cus_city,Cus_pro,Cus_country,Inv_ID")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Inv_ID"] = new SelectList(_context.Invoices, "Inv_ID", "Inv_ID", customer.Inv_ID);
            return(View(customer));
        }
        public async Task <ActionResult> Create([Bind(Include = "SiteSuperID,Name,Phone,Work")] SiteSuper siteSuper)
        {
            if (ModelState.IsValid)
            {
                db.SiteSupers.Add(siteSuper);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(siteSuper));
        }
        public async Task <ActionResult> Create([Bind(Include = "GenContractorID,Name")] GenContractor genContractor)
        {
            if (ModelState.IsValid)
            {
                db.GenContractors.Add(genContractor);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(genContractor));
        }
        public async Task <ActionResult> Create([Bind(Include = "EmployeeID,EmployeeNumber,FirstName,LastName,Address,City,ProvinceOrState,HomePhone,HomeCellPhone,WorkPhone,WorkCellPhone,EmergencyContactName,EmergencyContactPhone")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
        public async Task <ActionResult> Create([Bind(Include = "PMID,FirstName,LastName,Address,City,Province,Phone,WorkPhone")] PM pM)
        {
            if (ModelState.IsValid)
            {
                db.PMs.Add(pM);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(pM));
        }
        public async Task <ActionResult> Create([Bind(Include = "ContactId,ContactName,WorkPhone,WorkCellPhone")] PhoneBook phoneBook)
        {
            if (ModelState.IsValid)
            {
                db.PhoneBooks.Add(phoneBook);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(phoneBook));
        }
        public async Task <ActionResult> Create([Bind(Include = "SiteSuperID,Name,Phone,Work")] SiteSuper siteSuper)
        {
            if (ModelState.IsValid)
            {
                db.SiteSupers.Add(siteSuper);
                await db.SaveChangesAsync();

                AccountController.dynamicLogRecord(User.Identity.Name.ToString() + " created: " + "Site Super ID: " + siteSuper.SiteSuperID + " Site Super Name: " + siteSuper.Name + " Site Super Phone: " + siteSuper.Phone + " Site Super Work: " + siteSuper.Work, User.Identity.Name.ToString(), AccountController.setDynamicLog(User.Identity.Name));
                return(RedirectToAction("Index"));
            }

            return(View(siteSuper));
        }
        public async Task <ActionResult> Create([Bind(Include = "ForemanID,FirstName,LastName,Cell")] Foreman foreman)
        {
            if (ModelState.IsValid)
            {
                db.Foremen.Add(foreman);
                await db.SaveChangesAsync();

                AccountController.dynamicLogRecord(User.Identity.Name.ToString() + " created: " + "Foreman ID: " + foreman.ForemanID + " Foreman First Name: " + foreman.FirstName + " Foreman Last Name: " + foreman.LastName + " Foreman Cell: " + foreman.Cell, User.Identity.Name.ToString(), AccountController.setDynamicLog(User.Identity.Name));
                return(RedirectToAction("Index"));
            }

            return(View(foreman));
        }
Beispiel #17
0
        public async Task <ActionResult> Create([Bind(Include = "GenContractorID,Name")] GenContractor genContractor)
        {
            if (ModelState.IsValid)
            {
                db.GenContractors.Add(genContractor);
                await db.SaveChangesAsync();

                AccountController.dynamicLogRecord(User.Identity.Name.ToString() + " created: " + " Gen Contractor ID: " + genContractor.GenContractorID + " Gen Contractor Name: " + genContractor.Name, User.Identity.Name.ToString(), AccountController.setDynamicLog(User.Identity.Name));
                return(RedirectToAction("Index"));
            }

            return(View(genContractor));
        }
        public async Task <ActionResult> Create([Bind(Include = "PMID,FirstName,LastName,Address,City,Province,Phone,WorkPhone")] PM pM)
        {
            if (ModelState.IsValid)
            {
                db.PMs.Add(pM);
                await db.SaveChangesAsync();

                AccountController.dynamicLogRecord(User.Identity.Name.ToString() + " created: PMID: " + pM.PMID + " First Name: " + pM.FirstName + " Last Name: " + pM.LastName + " Address: " + pM.Address + " City: " + pM.City + " Province: " + pM.Province + " Phone: " + pM.Phone + " Work Phone: " + pM.WorkPhone, User.Identity.Name.ToString(), AccountController.setDynamicLog(User.Identity.Name));

                return(RedirectToAction("Index"));
            }

            return(View(pM));
        }
        public async Task <ActionResult> Create([Bind(Include = "EmployeeID,EmployeeNumber,FirstName,LastName,Address,City,ProvinceOrState,HomePhone,HomeCellPhone,WorkPhone,WorkCellPhone,EmergencyContactName,EmergencyContactPhone")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                await db.SaveChangesAsync();

                //Logging employee creation
                logger.Info(User.Identity.Name + " created " + employee.FirstName + " " + employee.LastName + " Values " + "Employee Number: " + employee.EmployeeNumber + " First Name: " + employee.FirstName + " Last Name: " + employee.LastName + " Address: " + employee.Address + " City: " + employee.City + " Province/State: " + employee.ProvinceOrState + " Home Phone: " + employee.HomePhone + " Home Cell Phone: " + employee.HomeCellPhone + " Work Phone: " + employee.WorkPhone + " Work Cell Phone: " + employee.WorkCellPhone + " Emergency Contact Name: " + employee.EmergencyContactName + " Emergency Contant Phone: " + employee.EmergencyContactPhone);
                AccountController.dynamicLogRecord(User.Identity.Name.ToString() + " created " + employee.FirstName + " " + employee.LastName + " Values " + "Employee Number: " + employee.EmployeeNumber + " First Name: " + employee.FirstName + " Last Name: " + employee.LastName + " Address: " + employee.Address + " City: " + employee.City + " Province/State: " + employee.ProvinceOrState + " Home Phone: " + employee.HomePhone + " Home Cell Phone: " + employee.HomeCellPhone + " Work Phone: " + employee.WorkPhone + " Work Cell Phone: " + employee.WorkCellPhone + " Emergency Contact Name: " + employee.EmergencyContactName + " Emergency Contant Phone: ", User.Identity.Name, AccountController.setDynamicLog(User.Identity.Name));

                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Beispiel #20
0
        public bool Update(Position position)
        {
            try
            {
                List <Position> positions = _mgmtContext.Position.Where(p => p.Id != position.Id && p.Position_Type == position.Position_Type).ToList();
                if (positions.Count() == 1)
                {
                    return(false);
                }

                _mgmtContext.Update(position);
                _mgmtContext.SaveChangesAsync();

                return(true);
            }
            catch (InvalidOperationException ioe)
            {
                Debug.WriteLine("Message " + ioe.Message);
                return(false);
            }
            catch (DbUpdateConcurrencyException dce)
            {
                Debug.WriteLine("Message " + dce.Message);
                return(false);
            }
        }
Beispiel #21
0
        public async Task <JobDb> AddJob(JobDb job)
        {
            job.Id = 0;
            var newJob = new JobDb {
                Id            = 0,
                Name          = job.Name,
                UserId        = job.UserId,
                ClientId      = job.ClientId,
                HoursReported = job.HoursReported
            };
            await _context.Jobs.AddAsync(newJob);

            await _context.SaveChangesAsync();

            return(job);
        }
Beispiel #22
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] AspNetUser aspNetUser)
        {
            if (ModelState.IsValid)
            {
                db.AspNetUsers.Add(aspNetUser);
                await db.SaveChangesAsync();

                //Log user being created (with username and Email)
                logger.Info(User.Identity.Name + " created " + aspNetUser.UserName + " " + aspNetUser.Email + " ");
                AccountController.dynamicLogRecord(User.Identity.Name.ToString() + " created " + aspNetUser.UserName + " " + aspNetUser.Email + " ", User.Identity.Name, AccountController.setDynamicLog(User.Identity.Name));

                return(RedirectToAction("Index"));
            }

            return(View(aspNetUser));
        }
        public async Task <IActionResult> Create([FromBody] Dish dish)
        {
            if (dish == null)
            {
                return(BadRequest());
            }
            try {
                _context.Dishes.Add(dish);
                await _context.SaveChangesAsync();

                return(Ok());
            } catch (DbUpdateException /* ex */) {
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(Json(new { error = "Ocorreu um erro interno, por favor tente novamente." }));
            }
        }
Beispiel #24
0
            public async Task <bool> Handle(AddGoodsCommand request, CancellationToken cancellationToken)
            {
                var goods = new Goods(request.Name);

                goods.CreateTime = DateTime.Now;
                // TODO: User
                goods.CreateUser     = _httpContext.HttpContext.User.Claims.FirstOrDefault(f => f.Type == "UserName").Value;
                goods.LastUpdateTime = DateTime.Now;
                // TODO: User
                goods.LastUpdateUser = "";


                var ImageIds = JsonConvert.DeserializeObject <List <Guid> >(request.ExtendValues["images"].ToString());

                var keys         = request.ExtendValues.Keys;
                var extendFields = _managementContext.GoodsExtendFields.Where(w => keys.Contains(w.Key));
                List <GoodsExtendAttribute> extendAttributes = new List <GoodsExtendAttribute>();

                foreach (var extendField in extendFields)
                {
                    string value = request.ExtendValues[extendField.Key]?.ToString();
                    if (!string.IsNullOrEmpty(value))
                    {
                        extendAttributes.Add(new GoodsExtendAttribute
                        {
                            GoodsId            = goods.Id,
                            GoodsExtendFieldId = extendField.Id,
                            Value = value
                        });
                    }
                }

                // 事务
                using IDbContextTransaction tran = _managementContext.Database.BeginTransaction();
                try
                {
                    // 更新图片
                    await _managementContext.GoodsImages.Where(w => w.GoodsId == goods.Id).ForEachAsync(f => f.GoodsId = null);

                    await _managementContext.GoodsImages.Where(w => ImageIds.Contains(w.Id)).ForEachAsync(f => f.GoodsId = goods.Id);

                    // 保存物品
                    await _managementContext.Goods.AddAsync(goods);

                    await _managementContext.GoodsExtendAttributes.AddRangeAsync(extendAttributes);

                    var result = await _managementContext.SaveChangesAsync();

                    await tran.CommitAsync();

                    return(result > 0);
                }
                catch (Exception)
                {
                    tran.Rollback();
                    // 保存错误 or 抛出错误
                }
                return(false);
            }
Beispiel #25
0
        public async Task <ActionResult> Create([Bind(Include = "JobID,JobNumber,JobName,LocationName,Address,City,ProvinceOrState,GenContractorContact,Foreman_ForemanID,GenContractor_GenContractorID,PM_PMID,Purchaser_PurchaserID,SiteSuper_SiteSuperID")] Job job)
        {
            if (ModelState.IsValid)
            {
                db.Jobs.Add(job);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.Foreman_ForemanID             = new SelectList(db.Foremen, "ForemanID", "FullName", job.Foreman_ForemanID);
            ViewBag.GenContractor_GenContractorID = new SelectList(db.GenContractors, "GenContractorID", "Name", job.GenContractor_GenContractorID);
            ViewBag.PM_PMID = new SelectList(db.PMs, "PMID", "FullName", job.PM_PMID);
            ViewBag.Purchaser_PurchaserID = new SelectList(db.Purchasers, "PurchaserID", "Name", job.Purchaser_PurchaserID);
            ViewBag.SiteSuper_SiteSuperID = new SelectList(db.SiteSupers, "SiteSuperID", "Name", job.SiteSuper_SiteSuperID);
            return(View(job));
        }
        public async Task <ActionResult> Create([Bind(Include = "HourRecordID,DateTime,Hours,Employee_EmployeeID,Job_JobID,Comment")] HourRecord hourRecord)
        {
            ApplicationDbContext context = new ApplicationDbContext();
            //used to see who is currently logged in
            UserManager <ApplicationUser> UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
            ApplicationUser currentUser = UserManager.FindById(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                hourRecord.Employee_EmployeeID = currentUser.Employee_EmployeeID;
                db.HourRecords.Add(hourRecord);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            //Possibly adding again for admin use?
            //ViewBag.Employee_EmployeeID = new SelectList(db.Employees, "EmployeeID", "FirstName", hourRecord.Employee_EmployeeID);

            return(View(hourRecord));
        }
Beispiel #27
0
        private async Task <string> updateToken(string username)
        {
            using (var db = new ManagementContext())
            {
                ManagementModel model = await db.management
                                        .Where(x => x.username == username)
                                        .SingleAsync();

                DateTime dt = DateTime.Now;
                if (dt.Subtract((DateTime)(model.token_update)).Minutes > 3)
                {
                    model.token        = Token.createToken();
                    model.token_update = DateTime.Now;
                    db.management.Update(model);
                    await db.SaveChangesAsync();
                }
                return(model.token);
            }
        }
Beispiel #28
0
            public async Task <GoodsExtendField> Handle(AddGoodsExtendFieldCommand request, CancellationToken cancellationToken)
            {
                var model = _mapper.Map <GoodsExtendField>(request);

                model.Key = request.Name.GetPinyin();

                model.CreateTime = DateTime.Now;
                // TODO: User
                model.CreateUser     = _httpContext.HttpContext.User.Claims.FirstOrDefault(f => f.Type == "UserName").Value;
                model.LastUpdateTime = DateTime.Now;
                // TODO: User
                model.LastUpdateUser = "";
                await _managementContext.GoodsExtendFields.AddAsync(model);

                if (await _managementContext.SaveChangesAsync() > 0)
                {
                    return(model);
                }
                return(null);
            }
        public bool Update(SubCompany subCompany)
        {
            try
            {
                _mgmtContext.Update(subCompany);
                _mgmtContext.SaveChangesAsync();

                return(true);
            }
            catch (InvalidOperationException ioe)
            {
                Debug.WriteLine("Message " + ioe.Message);
                return(false);
            }
            catch (DbUpdateConcurrencyException dce)
            {
                Debug.WriteLine("Message " + dce.Message);
                return(false);
            }
        }
Beispiel #30
0
        public async Task <ActionResult <LoginResponse> > Login(LoginRequest request)
        {
            ManagementModel model = null;

            using (var db = new ManagementContext())
            {
                model = await db.management
                        .Where(x => x.username.Contains(request.username))
                        .SingleAsync();

                if (model == null)
                {
                    return(NotFound());
                }

                // ハッシュ計算を行う
                string hash = calclateHashValue(request.password);
                if (!hash.Contains(model.hashnum))
                {
                    return(BadRequest());
                }

                // トークンを生成する
                DateTime dt = DateTime.Now;
                model.token        = Token.createToken();
                model.token_update = dt;
                model.last_login   = dt;
                db.management.Update(model);
                await db.SaveChangesAsync();

                return(new LoginResponse()
                {
                    token = model.token
                });
            }
        }