public async Task <IActionResult> PutConsultant(int id, Consultant consultant)
        {
            if (id != consultant.consultantId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#2
0
        public async Task <IActionResult> PutUserinfo([FromRoute] int id, [FromBody] Userinfo userinfo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userinfo.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutPrices([FromRoute] int id, [FromBody] Prices prices)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != prices.ProductId)
            {
                return(BadRequest());
            }

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


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

            return(NoContent());
        }
        public async Task <IActionResult> PutAffectation(int id, Affectation affectation)
        {
            if (id != affectation.AffectationId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("ProjectId,Name,Start,Deadline,Budget,Deposit,Status")] Projects projects)
        {
            if (ModelState.IsValid)
            {
                _context.Add(projects);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(projects));
        }
示例#6
0
        public async Task <Answers> Add(Answers answer)
        {
            try
            {
                var result = context.Answers.AddAsync(answer); // Change Tracking
                await context.SaveChangesAsync();              // Dit is een MUST

                //return result;  // NOK
                return(answer); // OK - ByRef -> De server returnt uw object education + een autoIdentity!
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null); // Niet vergeten!
            }
        }
示例#7
0
        public async Task <IActionResult> UpdateProduct(Product prod)
        {
            try
            {
                db.Entry(prod).State = EntityState.Modified;
                await db.SaveChangesAsync();

                MenuVM vm = new MenuVM();
                vm.userID = prod.FarmerID;
                return(View(vm));
            }
            catch (Exception e)
            {
                return(Content(e.Message));
            }
        }
        public async Task DeleteQuestionsByQuiz(Guid id)
        {
            try
            {
                var query = context.Questions.Where(e => e.QuizID == id);
                IEnumerable <Questions> result = await query.ToListAsync();

                foreach (Questions question in result)
                {
                    var delete = context.Questions.Remove(question);
                    await context.SaveChangesAsync();
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
            return;
        }
示例#9
0
        public async Task <IActionResult> Checkout(long id)
        {
            try
            {
                string key = "cart" + id.ToString();
                var    cacheEntryOptions = new MemoryCacheEntryOptions()
                                           .SetSlidingExpiration(TimeSpan.FromMinutes(10));
                Dictionary <Product, int> cart;
                if (!_cache.TryGetValue(key, out cart))
                {
                    cart = new Dictionary <Product, int>();
                    _cache.Set(key, cart, cacheEntryOptions);
                }
                User buyer = await db.Users.FindAsync(id);

                List <Product> keyList = new List <Product>(cart.Keys);
                Purchase       newPurchase;
                Sale           newSale;
                foreach (Product p in keyList)
                {
                    newPurchase = new Purchase(id, p.Name, cart[p]);
                    db.PurchaseHistory.Add(newPurchase);
                    await db.SaveChangesAsync();

                    newSale = new Sale(p.FarmerID, p.Name, cart[p], buyer.Address, buyer.Username);
                    db.SalesHistory.Add(newSale);
                    await db.SaveChangesAsync();

                    p.Stock          -= cart[p];
                    db.Entry(p).State = EntityState.Modified;
                    await db.SaveChangesAsync();
                }

                cart = new Dictionary <Product, int>();
                _cache.Set(key, cart, cacheEntryOptions);
                return(View(id));
            }
            catch (Exception e)
            {
                return(Content(e.Message));
            }
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("Id,Author,NameChange,ProjLanguage,LanguageChange,DevTime,ChangeCount")] ReportJournal reportJournal)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reportJournal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reportJournal));
        }
示例#11
0
        public IActionResult Post([FromBody] IDictionary <string, string> data)
        {
            var cli = new Client()
            {
                Name = data["name"], Description = data["description"]
            };
            var db = new ProjectDBContext();

            db.Client.Add(cli);
            db.SaveChangesAsync();
            return(RedirectToAction("Clients"));
        }
示例#12
0
        public async Task <IActionResult> SaveUser(User u)
        {
            try
            {
                if ((u.Username != "") && (u.Password != "") && (u.FirstName != "") && (u.LastName != "") &&
                    (u.Address != "") && (u.AccountNumber != ""))
                {
                    bool        validate = true;
                    List <User> userList = await db.Users.ToListAsync();

                    userList.ForEach(p =>
                    {
                        if (p.Username == u.Username && p.Password == u.Password)
                        {
                            validate = false;
                        }
                    });
                    if (validate)
                    {
                        db.Users.Add(u);
                        await db.SaveChangesAsync();

                        return(View());
                    }
                    else
                    {
                        return(Content("Ese usuario ya se encuentra registrado"));
                    }
                }
                else
                {
                    return(Content("No pueden haber campos vacios"));
                }
            }
            catch (Exception e)
            {
                return(Content(e.Message));
            }
        }
示例#13
0
        public IActionResult Delete(int id)
        {
            var db  = new ProjectDBContext();
            var cli = db.Project.FirstOrDefault(n => n.Id == id);

            if (cli == null)
            {
                return(new NotFoundObjectResult(cli));
            }
            db.Project.Remove(cli);
            db.SaveChangesAsync();
            return(Ok(null));
        }
示例#14
0
        public async Task <IActionResult> Create([Bind("EmployeeId,FirstName,LastName,Birthday,PhoneNumber,Position,Salary,Experiance,BeginningOfWork,Image,Description")] Employees employees)
        {
            if (ModelState.IsValid)
            {
                employees.CalculateMonthPaymentFrom = employees.BeginningOfWork;
                employees.Vacation = 0;
                employees.Overtime = 0;
                UploadPhoto(employees);
                _context.Add(employees);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employees));
        }
示例#15
0
 public IActionResult Delete(int ContactId)
 {
     using (var db = new ProjectDBContext())
     {
         var con = db.Contact.FirstOrDefaultAsync(n => n.Id == ContactId).Result;
         if (con == null)
         {
             return(new NotFoundObjectResult(con));
         }
         db.Contact.Remove(con);
         db.SaveChangesAsync();
     }
     return(Ok());
 }
示例#16
0
        public IActionResult Put(int id, [FromBody] IDictionary <string, string> data)
        {
            var db  = new ProjectDBContext();
            var cli = db.Client.FirstOrDefault(n => n.Id == id);

            if (cli == null)
            {
                return(new NotFoundObjectResult(cli));
            }
            cli.Name        = data["name"];
            cli.Description = data["description"];
            db.SaveChangesAsync();
            return(Ok(cli));
        }
示例#17
0
 public IActionResult Add(int clientId, [FromBody] IDictionary <string, string> data)
 {
     using (var db = new ProjectDBContext())
     {
         db.Contact.Add(new Contact()
         {
             ClientId  = clientId,
             Name      = data["name"],
             Surname   = data["surname"],
             Email     = data["email"],
             Telephone = data["telephone"]
         });
         db.SaveChangesAsync();
     }
     //change to redirect...
     return(Ok());
 }
示例#18
0
        public IActionResult Update(int ContactId, [FromBody] IDictionary <string, string> data)
        {
            using (var db = new ProjectDBContext())
            {
                Contact con = db.Contact.FirstOrDefaultAsync(n => n.Id == ContactId).Result;
                if (con != null)
                {
                    con.Name      = data["name"];
                    con.Surname   = data["surname"];
                    con.Email     = data["email"];
                    con.Telephone = data["telephone"];
                }
                db.SaveChangesAsync();
            }

            return(Ok());
        }
示例#19
0
        public IActionResult Post([FromBody] IDictionary <string, string> data)
        {
            var cli = new Models.Project()
            {
                Name = data["name"], Description = data["description"]
            };
            int a; if (int.TryParse(data["clientId"], out a))
            {
                cli.ClientId = a;
            }


            var db = new ProjectDBContext();

            db.Project.Add(cli);
            db.SaveChangesAsync();
            return(RedirectToAction("Projects"));
        }
示例#20
0
        public async Task <IActionResult> ChangePassword(UserWithNewPassword user)
        {
            if (ModelState.IsValid)
            {
                var currentUser = await _context.User.FirstAsync();

                if (currentUser.Login == user.Login && currentUser.Password == Encrypt(user.Password))
                {
                    try
                    {
                        currentUser.Password = Encrypt(user.NewPassword);

                        _context.Update(currentUser);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                    return(RedirectToAction("SignIn", "Login"));
                }
            }
            return(View(user));
        }
示例#21
0
        public async Task <IActionResult> AddorEdit(int Id,
                                                    [Bind("Id,Name,Language,Info,StartDate,EndDate,ProjectDataId,ReportJournalId")]
                                                    ProjectViewModel project)
        {
            if (ModelState.IsValid)
            {
                if (project.Id == 0)
                {
                    var userId = _userManager.GetUserId(this.HttpContext.User);
                    project.ProjectUserId = userId;

                    var projects = await _context.ProjectViewModel.Where(x => x.ProjectUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    var allChartData = await _context.ChartData.Where(x => x.ChartUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    var langTypes = projects.GroupBy(x => x.Language).ToList();

                    foreach (var c in allChartData)
                    {
                        if (userId == c.ChartUserId)
                        {
                            project.ProjectDataId = c.Id;

                            _context.Add(project);
                            _context.Update(c);
                            c.DataForProjects.Add(project);

                            await _context.SaveChangesAsync();

                            TempData["Message"] = "Project Created!";
                            return(View(project));
                        }

                        else
                        {
                            project.ProjectUserId = userId;

                            var newChartData = new ChartData
                            {
                                ChartUserId = userId
                            };

                            _context.Add(project);
                            _context.Add(newChartData);
                            project.ProjectDataId = newChartData.Id;
                            newChartData.DataForProjects.Add(project);
                            await _context.SaveChangesAsync();

                            TempData["Message"] = "Project Created!";
                            return(View(project));
                        }
                    }
                }

                else
                {
                    var userId          = _userManager.GetUserId(this.HttpContext.User);
                    var currentProjects = await _context.ProjectViewModel.Where(x => x.ProjectUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    var allCurrentChartData = await _context.ChartData.Where(x => x.ChartUserId.Equals(userId)).AsNoTracking().ToListAsync();

                    foreach (var c in allCurrentChartData)
                    {
                        _context.Update(project);
                        _context.Update(c);
                        await _context.SaveChangesAsync();

                        TempData["Message"] = "Project Updated!";
                        return(View(project));
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            else
            {
                TempData["Message"] = "Please try again.";
                return(RedirectToAction(nameof(AddorEdit)));
            }
        }