public async Task <ActionResult> PostStrumentoProvvisorio([FromBody] JObject data)
        {
            var desc      = data["Descrizione"].ToObject <string>();
            var strumento = data["Strumento"].ToObject <Strumento>();

            strumento.Status      = 1;
            strumento.Descrizione = desc;
            var s = new StrumentoProvvisorio();

            s.PartId      = strumento.PartId;
            s.SerialId    = strumento.SerialId;
            s.Descrizione = strumento.Descrizione;
            s.Status      = strumento.Status;
            s.Nome        = strumento.Nome;
            s.Marca       = strumento.Marca;
            s.Modello     = strumento.Modello;
            s.Posizione   = strumento.Posizione;
            s.TTL         = strumento.TTL;
            s.Delicato    = strumento.Delicato;
            if (strumento.PDFPath != null)
            {
                s.PDFPath = strumento.PDFPath;
            }
            if (strumento.ImgPath != null)
            {
                s.ImgPath = strumento.ImgPath;
            }
            _context.StrumentoProvvisorio.Add(s);
            await _context.SaveChangesAsync();

            return(Ok());
        }
예제 #2
0
        public async Task <ActionResult> PostPrenotazione()
        {
            Prenotazione prenotazione = new Prenotazione();

            _context.Prenotazione.Add(prenotazione);
            _context.SaveChanges();
            var user = await _userManager.FindByIdAsync(User.Claims.First(c => c.Type == "UserID").Value);

            prenotazione.Utente = user;
            ICollection <DettaglioPrenotazione> strumenti = SessionHelper.GetObjectFromJson <ICollection <DettaglioPrenotazione> >(HttpContext.Session, "cart");

            if (strumenti.Count == 0)
            {
                return(BadRequest());
            }
            foreach (var d in strumenti)
            {
                var s = _context.Strumento.Find(d.IdStrumento);
                d.IdPrenotazione = prenotazione.ID;
                d.Prenotazione   = prenotazione;
                d.Strumento      = s;
                _context.DettaglioPrenotazione.Add(d);
                await _context.SaveChangesAsync();
            }
            prenotazione.Strumenti = strumenti;


            await _context.SaveChangesAsync();

            SessionHelper.Reset(HttpContext.Session, "cart");

            return(Ok());
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Phone,Address")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Site")] Delivery delivery)
        {
            if (ModelState.IsValid)
            {
                _context.Add(delivery);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(delivery));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,StreetAddress,ZipCode,City,Country,Ssn,PhoneNumber1,PhoneNumber2,Email")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(IndexSearch)));
            }
            return(View(person));
        }
        public async Task <IActionResult> Create([Bind("Id,ProductId,TagId")] ProductTag productTag)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productTag);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Description", productTag.ProductId);
            ViewData["TagId"]     = new SelectList(_context.Tags, "Id", "Name", productTag.TagId);
            return(View(productTag));
        }
예제 #8
0
        public async Task <IActionResult> Create([Bind("Id,ProductId,CustomerId,DeliveryId,Time")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Address", order.CustomerId);
            ViewData["DeliveryId"] = new SelectList(_context.Deliveries, "Id", "Name", order.DeliveryId);
            ViewData["ProductId"]  = new SelectList(_context.Products, "Id", "Description", order.ProductId);
            return(View(order));
        }
예제 #9
0
        public async Task <IActionResult> Stop([Required] int cId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无课程管理操作权限"
                    }));
                }

                Cource cource = _context.Cources.Find(cId);
                if (cource != null)
                {
                    cource.CourceStatus = CourceStatus.Normal;
                    await _context.SaveChangesAsync();

                    return(Json(new
                    {
                        isOk = true,
                        title = "消息提示",
                        message = "修改成功!"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "资源不存在,或者已经被删除了"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
예제 #10
0
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Client).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientExists(Client.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
예제 #11
0
        private void SaveEmployees_Click(object sender, RoutedEventArgs e)
        {
            if (DG1 != null && DG1.Items != null && unitOfWork.EmployeesUnits != null)
            {
                using (LabContext db = new LabContext())
                {
                    unitOfWork.EmployeesUnits._EmployeesContext = db;
                    using (var transaction = unitOfWork.EmployeesUnits._EmployeesContext.Database.BeginTransaction())
                    {
                        try
                        {
                            foreach (var employee in unitOfWork.EmployeesUnits.ListOfEmployees)
                            {
                                if (employee is Employee)
                                {
                                    if (unitOfWork.EmployeesUnits._EmployeesContext.Employees.Any(x => x.Id == employee.Id))
                                    {
                                        var emp = unitOfWork.EmployeesUnits._EmployeesContext.Employees.FirstOrDefault(el => el.Id == employee.Id);
                                        if (emp != null)
                                        {
                                            unitOfWork.EmployeesUnits._EmployeesContext.Employees.Attach(emp);
                                            emp.Name        = employee.Name;
                                            emp.Post        = employee.Post;
                                            emp.Wage        = employee.Wage;
                                            emp.Age         = employee.Age;
                                            emp.CompanyName = employee.CompanyName;
                                        }
                                        unitOfWork.EmployeesUnits._EmployeesContext.SaveChanges();
                                    }
                                    else
                                    {
                                        unitOfWork.EmployeesUnits.Save(employee);
                                    }
                                }
                            }

                            foreach (var employee in unitOfWork.EmployeesUnits._EmployeesContext.Employees.ToList())
                            {
                                if (!unitOfWork.EmployeesUnits.ListOfEmployees.Any(elDG => elDG.Id == employee.Id))
                                {
                                    unitOfWork.EmployeesUnits._EmployeesContext.Employees.Remove(employee);
                                }
                            }
                            transaction.Commit();
                            unitOfWork.EmployeesUnits._EmployeesContext.SaveChanges();
                            db.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
예제 #12
0
 private void ShowCompanies_Click(object sender, RoutedEventArgs e)
 {
     using (LabContext db = new LabContext())
     {
         unitOfWork.CompaniesUnits._CompaniesContext = db;
         unitOfWork.CompaniesUnits.ListOfCompanies   = unitOfWork.CompaniesUnits._CompaniesContext.Companies.ToList();
         DG2.DataContext = unitOfWork.CompaniesUnits.ListOfCompanies;
         db.SaveChangesAsync();
     }
 }
예제 #13
0
 private void ShowEmployees_Click(object sender, RoutedEventArgs e)
 {
     using (LabContext db = new LabContext())
     {
         unitOfWork.EmployeesUnits._EmployeesContext = db;
         unitOfWork.EmployeesUnits.ListOfEmployees   = unitOfWork.EmployeesUnits._EmployeesContext.Employees.ToList();
         DG1.DataContext = unitOfWork.EmployeesUnits.ListOfEmployees;
         db.SaveChangesAsync();
     }
 }
예제 #14
0
        private void SaveCompanies_Click(object sender, RoutedEventArgs e)
        {
            if (DG2 != null && DG2.Items != null && unitOfWork.CompaniesUnits != null)
            {
                using (LabContext db = new LabContext())
                {
                    unitOfWork.CompaniesUnits._CompaniesContext = db;
                    unitOfWork.EmployeesUnits._EmployeesContext = db;
                    foreach (var company in unitOfWork.CompaniesUnits.ListOfCompanies)
                    {
                        if (company is Company)
                        {
                            if (unitOfWork.CompaniesUnits._CompaniesContext.Companies.Any(x => x.Name == company.Name))
                            {
                                var el  = unitOfWork.CompaniesUnits._CompaniesContext.Companies.FirstOrDefault(elDB => elDB.Name == company.Name);
                                var emp = unitOfWork.EmployeesUnits._EmployeesContext.Employees.FirstOrDefault(empDB => empDB.CompanyName == el.Name);
                                if (emp != null)
                                {
                                    unitOfWork.EmployeesUnits._EmployeesContext.Employees.Attach(emp);
                                    emp.CompanyName = company.Name;
                                }
                                if (el != null)
                                {
                                    unitOfWork.CompaniesUnits._CompaniesContext.Companies.Attach(el);
                                    el.Cost   = company.Cost;
                                    el.Adress = company.Adress;
                                    el.Name   = company.Name;
                                }
                                unitOfWork.EmployeesUnits._EmployeesContext.SaveChanges();
                                unitOfWork.CompaniesUnits._CompaniesContext.SaveChanges();
                            }
                            else
                            {
                                unitOfWork.CompaniesUnits.Save(company);
                            }
                        }
                    }

                    foreach (var el in unitOfWork.CompaniesUnits._CompaniesContext.Companies.ToList())
                    {
                        if (!unitOfWork.CompaniesUnits.ListOfCompanies.Any(elDG => el.Name == elDG.Name))
                        {
                            if (unitOfWork.EmployeesUnits.ListOfEmployees.Any(elDG => elDG.CompanyName == el.Name))
                            {
                                unitOfWork.EmployeesUnits._EmployeesContext.Employees.RemoveRange(unitOfWork.EmployeesUnits._EmployeesContext.Employees.Where(x => x.CompanyName == el.Name));
                            }
                            unitOfWork.CompaniesUnits._CompaniesContext.Companies.Remove(el);
                        }
                    }
                    unitOfWork.EmployeesUnits._EmployeesContext.SaveChanges();
                    unitOfWork.CompaniesUnits._CompaniesContext.SaveChanges();
                    db.SaveChangesAsync();
                }
            }
        }
예제 #15
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Car.Add(Car);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
예제 #16
0
        public async Task <IActionResult> AuthorizeDelicata(string idStr, int idPre)
        {
            var dettaglio = _context.DettaglioPrenotazione.Where(dp => dp.IdStrumento == idStr && dp.IdPrenotazione == idPre).ToList().FirstOrDefault();

            if (!(await checkPrenotazioniStrumento(idStr, idPre, dettaglio.dataInizio, dettaglio.dataFine)))
            {
                return(BadRequest());
            }
            dettaglio.Checked = true;
            _context.DettaglioPrenotazione.Update(dettaglio);
            await _context.SaveChangesAsync();

            return(Ok());
        }
예제 #17
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Client = await _context.Client.FindAsync(id);

            if (Client != null)
            {
                _context.Client.Remove(Client);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
예제 #18
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            IssuedCar = await _context.IssuedCar.FindAsync(id);

            if (IssuedCar != null)
            {
                _context.IssuedCar.Remove(IssuedCar);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
예제 #19
0
        private void SearchCompanies_Click(object sender, RoutedEventArgs e)
        {
            Company findingObject = null;
            var     list          = new List <Company>();

            using (LabContext db = new LabContext())
            {
                unitOfWork.CompaniesUnits._CompaniesContext = db;
                if (CompanyNameTxtBlock.Text.Count() != 0)
                {
                    findingObject = unitOfWork.CompaniesUnits._CompaniesContext.Companies.Find(CompanyNameTxtBlock.Text);
                }

                if (CompanyCostTxtBlock.Text.Count() != 0)
                {
                    int cost = 0;
                    if (Int32.TryParse(CompanyCostTxtBlock.Text, out cost))
                    {
                        if (CompanyNameTxtBlock.Text.Count() == 0)
                        {
                            list = unitOfWork.CompaniesUnits._CompaniesContext.Companies.ToList().Where(x => x.Cost <= cost).ToList();
                        }
                        else
                        {
                            if (findingObject != null && findingObject.Cost <= cost)
                            {
                                list.Add(findingObject);
                            }
                        }
                    }
                }
                else
                {
                    if (findingObject != null)
                    {
                        list.Add(findingObject);
                    }
                }

                DG2.DataContext = list;

                unitOfWork.CompaniesUnits._CompaniesContext.SaveChangesAsync();
                db.SaveChangesAsync();
            }
        }
예제 #20
0
        private void SearchEmployee_Click(object sender, RoutedEventArgs e)
        {
            Employee findingObject = null;
            var      list          = new List <Employee>();

            using (LabContext db = new LabContext())
            {
                unitOfWork.EmployeesUnits._EmployeesContext = db;
                if (EmpNameTxtBox.Text.Count() != 0)
                {
                    findingObject = unitOfWork.EmployeesUnits._EmployeesContext.Employees.Where(x => x.Name == EmpNameTxtBox.Text).FirstOrDefault();
                }

                if (EmpAgeTxtBox.Text.Count() != 0)
                {
                    int age = 0;
                    if (Int32.TryParse(EmpAgeTxtBox.Text, out age))
                    {
                        if (EmpNameTxtBox.Text.Count() == 0)
                        {
                            list = unitOfWork.EmployeesUnits._EmployeesContext.Employees.ToList().Where(x => x.Age <= age).ToList();
                        }
                        else
                        {
                            if (findingObject != null && findingObject.Age <= age)
                            {
                                list.Add(findingObject);
                            }
                        }
                    }
                }
                else
                {
                    if (findingObject != null)
                    {
                        list.Add(findingObject);
                    }
                }

                DG1.DataContext = list;

                unitOfWork.EmployeesUnits._EmployeesContext.SaveChangesAsync();
                db.SaveChangesAsync();
            }
        }
예제 #21
0
 public async Task <IActionResult> Log([Required] int terminal, [Required] String uId)
 {
     if (ModelState.IsValid && terminal < 3 && terminal >= 0)
     {
         LogUserLogin log = new LogUserLogin
         {
             ID        = uId,
             Terminal  = (Terminal)terminal,
             LoginIp   = _accessor.HttpContext.Connection.RemoteIpAddress.ToString(),
             LoginTime = DateTime.Now
         };
         _context.LogUserLogin.Add(log);
         await _context.SaveChangesAsync();
     }
     return(Json(new
     {
         logResult = true
     }));
 }
        public async Task <IActionResult> AbilitaStrumento(string id)
        {
            var strumento = _context.Strumento.Find(id);

            if (strumento == null)
            {
                return(NotFound());
            }
            if (strumento.Status == 0)
            {
                var newTtl = strumento.TTL.AddYears(1);
                strumento.TTL = newTtl;
            }

            strumento.Status = 1;

            _context.Strumento.Update(strumento);
            await _context.SaveChangesAsync();


            return(Ok());
        }
예제 #23
0
 public async Task <int> LoggerAsync(LogPricipalOperation operation)
 {
     _context.LogPricipalOperations.Add(operation);
     return(await _context.SaveChangesAsync());
 }
예제 #24
0
        /// <summary>
        /// 创建一个新的学院
        /// </summary>
        /// <param name="name"></param>
        /// <param name="moduleId"></param>
        /// <returns></returns>
        public async Task <IActionResult> Create([Required] String name, [Required] int moduleId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "你并无信息管理操作权限"
                    }));
                }

                if (_context.Modules.Any(m => m.ModuleId == moduleId))
                {
                    if (_context.Institute.Any(ins => ins.Name == name))
                    {
                        return(Json(new
                        {
                            isOk = false,
                            error = "新建学院名称重复,已经存在此学院"
                        }));
                    }
                    else
                    {
                        LogPricipalOperation log =
                            _logger.GetDefaultLogPricipalOperation(
                                PrincpalOperationCode.InstituteAdd,
                                $"添加新的学院",
                                $"添加新的学院名称 {name}");

                        log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                        _context.LogPricipalOperations.Add(log);
                        Institute institute = new Institute {
                            Name = name
                        };
                        _context.Institute.Add(institute);
                        await _context.SaveChangesAsync().ContinueWith(t =>
                        {
                            int result = t.Result;
                            if (result == 1)
                            {
                                InstituteToModule instituteToModule = new InstituteToModule();
                                instituteToModule.ModuleId          = moduleId;
                                instituteToModule.InstituteId       = institute.InstituteId;
                                _context.Add(instituteToModule);
                                _context.SaveChangesAsync();
                            }
                        });

                        return(Json(new
                        {
                            isOk = true,
                        }));
                    }
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "不存在此模块!学院不可属于此模块"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = "参数错误"
                }));
            }
        }
예제 #25
0
        public async Task <IActionResult> Create([Required] String name)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                    {
                        return(Json(new
                        {
                            isOk = false,
                            error = "你并无信息管理操作权限"
                        }));
                    }

                    LogPricipalOperation operation = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.AddModule, $"添加模块 模块名称{name.Trim()}", $"添加新的的模块:{name.Trim()}");

                    if (_context.Modules.FirstOrDefault(m => m.Name.Equals(name)) == null)
                    {
                        operation.PrincpalOperationStatus = PrincpalOperationStatus.Success;

                        Module module = new Module {
                            AddTime = DateTime.Now, Name = name.Trim(), PrincipalId = _analysis.GetLoginUserModel(HttpContext).UserId
                        };

                        _context.LogPricipalOperations.Add(operation);
                        _context.Modules.Add(module);

                        await _context.SaveChangesAsync().ContinueWith(r =>
                        {
                            /* 考试出题配置 */
                            SystemSetting setting = _config.LoadSystemSetting();
                            ModuleExamSetting mes = SystemSetting.GetDefault();
                            mes.ModuleId          = module.ModuleId;
                            mes.ModuleName        = module.Name;
                            setting.ExamModuleSettings.Add(module.ModuleId, mes);
                            _config.ReWriteSystemSetting(setting);

                            /* 考试开放配置 */
                            Dictionary <int, ExamOpenSetting> es = _config.LoadModuleExamOpenSetting();
                            ExamOpenSetting examSetting          = new ExamOpenSetting();
                            examSetting.ModuleId   = module.ModuleId;
                            examSetting.IsOpen     = false;
                            examSetting.ModuleName = module.Name;
                            es.Add(module.ModuleId, examSetting);
                            _config.ReWriteModuleExamOpenSetting(es);
                        });

                        return(Json(new
                        {
                            isOk = true
                        }));
                    }
                    else
                    {
                        await _logger.LoggerAsync(operation);

                        return(Json(new
                        {
                            isOk = false,
                            error = "模块名重复,此模块已经存在"
                        }));
                    }
                }
                else
                {
                    return(RedirectToAction("ParameterError", "Error"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #26
0
        public async Task <IActionResult> Link([Bind(include: "Name,CourceId,Description,LengthOfStudy,ResourceUrl,ResourceType")] Resource resource)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无课程管理操作权限"
                    }));
                }
                #region 功能实现区域

                LogPricipalOperation operation =
                    _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.AddResource,
                                                           $"查询编码:无", "添加课程资源:资源链接{resource.ResourceUrl}");

                if (_context.Cources.Any(c => c.CourceId == resource.CourceId))
                {
                    if (_context.Resources.Any(r => r.Name == resource.Name && r.ResourceType == ResourceType.Link))
                    {
                        await _context.LogPricipalOperations.AddAsync(operation).ContinueWith(async r =>
                        {
                            await _context.SaveChangesAsync();
                        });


                        return(Json(new
                        {
                            isOk = false,
                            title = "错误提示",
                            message = "此名称的资源已经存在"
                        }));
                    }

                    resource.Name           = resource.Name.Trim();
                    resource.Description    = resource.Description.Trim();
                    resource.ResourceUrl    = resource.ResourceUrl.Trim();
                    resource.ResourceStatus = ResourceStatus.Normal;
                    resource.AddTime        = DateTime.Now;
                    resource.PrincipalId    = _analysis.GetLoginUserModel(HttpContext).UserId;
                    _context.Resources.Add(resource);

                    await _context.SaveChangesAsync().ContinueWith(result =>
                    {
                        operation.PrincpalOperationContent = $"添加资源ID {resource.ResourceId}";
                        operation.PrincpalOperationStatus  = PrincpalOperationStatus.Success;
                        _context.LogPricipalOperations.Add(operation);
                        _context.SaveChanges();
                    });

                    return(Json(new
                    {
                        isOk = true,
                        title = "消息提示",
                        message = "添加成功"
                    }));
                }
                else
                {
                    _context.LogPricipalOperations.Add(operation);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "资源所属课程不存在或者已经被删除!"
                    }));
                }
                #endregion
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }