Example #1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Description,Due_Date,Project,Owner,Asignee,Status,Review")] MyTask myTask)
        {
            if (id != myTask.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(myTask);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MyTaskExists(myTask.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction("Dashboard", "Users", UsersController.logged_user);
                //return RedirectToAction("Index");
                ViewBag.Message = string.Format("Your changes have been saved");
            }
            return(View(myTask));
        }
Example #2
0
 public async Task <IActionResult> Edit(Guid Id, string first_name, string last_name, string username, string encrypted_password, IFormFile PictureFile, int age, string other_ocupation, string email, string picture_path, RatingType rating, string phone_number)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (logged_user.username == username)
             {
                 var updated = _context.User.Find(logged_user.Id);
                 if (PictureFile != null)
                 {
                     string fileName  = Path.GetFileNameWithoutExtension(PictureFile.FileName);
                     string extension = Path.GetExtension(PictureFile.FileName);
                     fileName = fileName + DateTime.Now.ToString("yymmssffff") + extension;
                     //user.picture_path = "~/Content/Images/" + fileName;
                     updated.picture_path = "C:/Users/bherle/source/repos/MyPlanner/MyPlanner/wwwroot/Content/Images/" + fileName;
                     updated.PictureFile.CopyTo(new FileStream(picture_path, FileMode.Create));
                 }
                 updated.first_name      = first_name;
                 updated.last_name       = last_name;
                 updated.username        = username;
                 updated.age             = age;
                 updated.other_ocupation = other_ocupation;
                 updated.phone_number    = phone_number;
                 updated.email           = email;
                 _context.Update(updated);
                 await _context.SaveChangesAsync();
             }
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!UserExists(Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         ViewBag.Message = string.Format("Your changes have been saved");
         return(RedirectToAction(nameof(Index)));
     }
     return(View(logged_user));
 }
Example #3
0
 public async Task <IActionResult> Edit(Guid id, [Bind("id,name,username,encrypted_password,age,other_ocupation")] User user)
 {
     if (id != user.id)
     {
         return(NotFound());
     }
     if (logged_user.id == user.id)
     {
         if (ModelState.IsValid)
         {
             try
             {
                 var updated = _context.User.Find(user.id);
                 updated.name            = user.name;
                 updated.username        = user.username;
                 updated.age             = user.age;
                 updated.other_ocupation = user.other_ocupation;
                 _context.Update(updated);
                 await _context.SaveChangesAsync();
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!UserExists(user.id))
                 {
                     return(NotFound());
                 }
                 else
                 {
                     throw;
                 }
             }
             return(RedirectToAction(nameof(Index)));
         }
     }
     return(View(user));
 }
        public async Task <IActionResult> Edit(Guid id, string Description, DateTime Due_Date, string Owner, string Location, RatingType Rating, RatingType RatingOwn, MyTask.FakeBoolType Transfer, int Duration, MyTask.FakeBoolType Physical_Effort, MyTask.TagType Tag, string Asignee, MyTask.StatusType Status, float Price)
        {
            var  myTask  = _context.MyTask.Find(id);
            bool msg_err = false;

            if (id != myTask.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var    user_asgn = _context.User.FirstOrDefault(m => m.username == Asignee);
                string asgn_name = null;
                if (user_asgn != null)
                {
                    asgn_name = user_asgn.username;
                }
                else
                {
                    if (!string.IsNullOrEmpty(Asignee))
                    {
                        ViewBag.Message = string.Format("User does not exist");
                        return(View(myTask));
                    }
                }
                var user_own = await _context.User.FirstOrDefaultAsync(n => n.username == Owner);

                string own_name = null;
                if (user_own != null)
                {
                    own_name = user_own.username;
                }
                else
                {
                    ViewBag.Message = string.Format("User does not exist");
                    return(View(myTask));
                }

                if (UsersController.logged_user.username == asgn_name || UsersController.logged_user.username == own_name)
                {
                    if (Description != myTask.Description)
                    {
                        myTask.Description = Description;
                    }
                    if (Due_Date != myTask.Due_Date)
                    {
                        myTask.Due_Date = Due_Date;
                    }
                    if (Owner != myTask.Owner)
                    {
                        myTask.Owner = Owner;
                    }
                    if (Location != myTask.Location)
                    {
                        myTask.Location = Location;
                    }
                    if (Tag != myTask.Tag)
                    {
                        myTask.Tag = Tag;
                    }
                    if (Asignee != myTask.Asignee)
                    {
                        myTask.Asignee = Asignee;
                    }
                    if (Status != myTask.Status)
                    {
                        myTask.Status = Status;
                    }

                    if (Rating != RatingType.NoRating && user_asgn != null)
                    {
                        myTask.Rating          = Rating;
                        myTask.RatingInt       = (int)Rating;
                        user_asgn.rating_float = (user_asgn.no_ratings * user_asgn.rating_float + (int)Rating) / (user_asgn.no_ratings + 1);
                        user_asgn.rating_float = (float)Math.Round(user_asgn.rating_float, 2);
                        user_asgn.no_ratings   = user_asgn.no_ratings + 1;
                    }

                    /* else
                     * {
                     *   ViewBag.Message = string.Format("Rating cannot be changed");
                     *   msg_err = true;
                     * }*/
                    if (RatingOwn != RatingType.NoRating && user_own != null)
                    {
                        myTask.RatingOwn      = RatingOwn;
                        myTask.RatingOwnInt   = (int)RatingOwn;
                        user_own.rating_float = (user_own.no_ratings * user_own.rating_float + (int)RatingOwn) / (user_own.no_ratings + 1);
                        user_own.rating_float = (float)Math.Round(user_own.rating_float, 2);
                        user_own.no_ratings   = user_own.no_ratings + 1;
                    }

                    /*  else
                     * {
                     *    ViewBag.Message = string.Format("Rating cannot be changed");
                     *    msg_err = true;
                     * } */
                    if (Transfer != myTask.Transfer)
                    {
                        myTask.Transfer = Transfer;
                    }
                    if (Duration != myTask.Duration)
                    {
                        myTask.Duration = Duration;
                    }
                    if (Physical_Effort != myTask.Physical_Effort)
                    {
                        myTask.Physical_Effort = Physical_Effort;
                    }
                    if (Price != 0)
                    {
                        myTask.Price = Price;
                        Weights         weights;
                        LocationWeights location_weights;

                        IQueryable <Weights> weightsQuery = from w in _context.Weights
                                                            select w;
                        var temp_weights = new List <Weights>(await weightsQuery.ToListAsync());
                        weights = temp_weights.Last(cat => cat.tag == myTask.Tag);

                        IQueryable <LocationWeights> l_weightsQuery = from l_w in _context.LocationWeights
                                                                      select l_w;
                        var temp_l_weights   = new List <LocationWeights>(await l_weightsQuery.ToListAsync());
                        var loc_weights_list = temp_l_weights.Where(loc => loc.location == myTask.Location);
                        location_weights = loc_weights_list.Last(cat => cat.tag == myTask.Tag);

                        IQueryable <Weights> last_w_query = from lw in _context.Weights
                                                            select lw;
                        var temp_last_w = new List <Weights>(await last_w_query.ToListAsync());
                        int last_w_id   = temp_last_w.Last().Id; //get last id for saving new weights

                        IQueryable <LocationWeights> last_loc_w_query = from loc_w in _context.LocationWeights
                                                                        select loc_w;
                        var temp_last_loc_w = new List <LocationWeights>(await last_loc_w_query.ToListAsync());
                        int last_loc_w_id   = temp_last_loc_w.Last().Id; //get last id for saving new location weights

                        myTask.BackPropagation(weights.b0, location_weights.b1, weights.w0_0, weights.w0_1, weights.w0_2, weights.w0_3, location_weights.w1_1, myTask.Price, location_weights.location, _context, last_w_id, last_loc_w_id, myTask.Tag);
                    }

                    try
                    {
                        if (user_asgn != null)
                        {
                            _context.Update(user_asgn);
                        }
                        _context.Update(myTask);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!MyTaskExists(myTask.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    msg_err = true;
                }

                //return RedirectToAction("Dashboard", "Users", UsersController.logged_user);
                //return RedirectToAction("Index");
                if (!msg_err)
                {
                    return(RedirectToAction("Dashboard", "Users", UsersController.logged_user));
                }
                else
                {
                    ViewBag.Message = string.Format("You are not allowed to change this information");
                    return(View(myTask));
                }
            }
            else
            {
                throw new System.Web.Http.HttpResponseException(System.Net.HttpStatusCode.BadRequest);
            }
        }