Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Description,Due_Date,Project,Owner,Asignee,Status,Review")] MyTask myTask)
        {
            if (ModelState.IsValid)
            {
                myTask.Id = Guid.NewGuid();
                _context.Add(myTask);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(myTask));
        }
Ejemplo n.º 2
0
 public async Task <IActionResult> Create([Bind("id,name,username,encrypted_password")] User user)
 {
     if (ModelState.IsValid)
     {
         user.id = Guid.NewGuid();
         user.encrypted_password = SecurePasswordHasherHelper.Hash(user.encrypted_password);
         if (!use_test_repository)
         {
             _context.Add(user);
             await _context.SaveChangesAsync();
         }
         else
         {
             _repository.AddItem(user);
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(user));
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("id,first_name,last_name,username,encrypted_password,PictureFile,age,other_ocupation,email,picture_path,rating,phone_number")] User user)
        {
            if (ModelState.IsValid)
            {
                user.Id = Guid.NewGuid();
                user.encrypted_password = SecurePasswordHasherHelper.Hash(user.encrypted_password);
                string fileName  = Path.GetFileNameWithoutExtension(user.PictureFile.FileName);
                string extension = Path.GetExtension(user.PictureFile.FileName);
                fileName = fileName + DateTime.Now.ToString("yymmssffff") + extension;
                //user.picture_path = "~/Content/Images/" + fileName;
                string temp_path = "C:/Users/bherle/source/repos/MyPlanner/MyPlanner/wwwroot/Content/Images/" + fileName;
                user.picture_path = "/Content/Images/" + fileName;
                user.PictureFile.CopyTo(new FileStream(temp_path, FileMode.Create));
                _context.Add(user);
                logged_user = user;
                await _context.SaveChangesAsync();

                ModelState.Clear();
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Description,Due_Date,Owner,Location,Urgency,Transfer,Duration,Physical_Effort,Tag,Asignee,Status,Rating")] MyTask myTask)
        {
            if (ModelState.IsValid)
            {
                myTask.Id = Guid.NewGuid();
                var user_own = await _context.User.FirstOrDefaultAsync(n => n.username == myTask.Owner);

                if (user_own == null)
                {
                    ViewBag.Message = string.Format("Owner does not exist");
                    return(View(myTask));
                }
                if (myTask.Due_Date < DateTime.Today)
                {
                    ViewBag.Message = string.Format("Date smaller than today");
                    return(View(myTask));
                }
                IQueryable <LocationWeights> location_query = from locations in _context.LocationWeights where locations.location == myTask.Location
                                                              select locations;
                var location_exist = new List <LocationWeights>(await location_query.ToListAsync());
                if (!(location_exist.Any()))
                {
                    ViewBag.Message = string.Format("Location unavailable");
                    return(View(myTask));
                }
                _context.Add(myTask);
                await _context.SaveChangesAsync();

                //return View(myTask);
                return(RedirectToAction("Edit", new { id = myTask.Id }));
            }
            else
            {
                throw new System.Web.Http.HttpResponseException(System.Net.HttpStatusCode.BadRequest);
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Index(string contact, string selected_contact, string message_text, string new_received, string contact_received)
        {
            /*  var result = await pusher.TriggerAsync(
             *   "my-channel",
             *   "my-event",
             *   new { message = "hello world" });
             */
            // return new HttpStatusCodeResult((int)HttpStatusCode.OK);
            conv_model.receive_channel = UsersController.logged_user.username;

            IQueryable <Message> convQuery5 = from r in _context.Message
                                              select r;
            var temp5   = new List <Message>(await convQuery5.ToListAsync());
            int last_id = temp5.Last().Id; //get last id for saving new messages

            conv_model.contacts_list = new List <UserBasic>();
            conv_model.messages      = new List <Text>();

            IQueryable <string> convQuery = from m in _context.Message // find logged_user's messages
                                            orderby m.Receiver
                                            where m.Sender == UsersController.logged_user.username
                                            select m.Receiver;

            var temp1 = new List <string>(await convQuery.Distinct().ToListAsync());
            IQueryable <string> convQuery2 = from n in _context.Message // find logged_user's contacts
                                             orderby n.Sender
                                             where n.Receiver == UsersController.logged_user.username
                                             select n.Sender;
            var temp2 = new List <string>(await convQuery2.Distinct().ToListAsync());

            foreach (var item in temp2)
            {
                temp1.Append(item);
            }
            conv_model.contacts = new List <string>(temp1.Distinct().ToList());

            if (!string.IsNullOrEmpty(message_text)) //add to recent list selected contact
            {
                conv_model.contacts_list.Add(new UserBasic(temp_contact));
            }
            else //populate recent list if no selected_contact
            {
                foreach (var item in conv_model.contacts)
                {
                    if (!string.IsNullOrEmpty(contact))
                    {
                        if (item.Contains(contact))
                        {
                            conv_model.contacts_list.Add(new UserBasic(item));
                            if (string.IsNullOrEmpty(temp_contact))
                            {
                                temp_contact = item;
                            }
                        }
                    }
                    else
                    {
                        //var last_message = _context.Message.LastOrDefault(x => (x.Receiver == UsersController.logged_user.username && x.Sender == item) || (x.Sender == UsersController.logged_user.username && x.Receiver == item));
                        IQueryable <Message> convQuery4 = from q in _context.Message
                                                          orderby q.Date_created
                                                          where (q.Receiver == item && q.Sender == UsersController.logged_user.username) || (q.Receiver == UsersController.logged_user.username && q.Sender == item)
                                                          select q;
                        var temp4 = new List <Message>(await convQuery4.ToListAsync());
                        var local_last_message = temp4.Last();
                        conv_model.contacts_list.Add(new UserBasic(item, local_last_message.Text, local_last_message.Date_created));
                        if (string.IsNullOrEmpty(temp_contact))
                        {
                            temp_contact = item;
                        }
                    }
                }
                conv_model.Sort();
            }

            if (!string.IsNullOrEmpty(selected_contact)) //add to recent list selected contact
            {
                temp_contact = selected_contact;
                if (conv_model.contacts_list.Count == 0)
                {
                    conv_model.contacts_list.Add(new UserBasic(selected_contact));
                }
            }

            if (!string.IsNullOrEmpty(temp_contact)) //show conversation
            {
                IQueryable <Message> convQuery3 = from p in _context.Message
                                                  orderby p.Date_created
                                                  where (p.Receiver == temp_contact && p.Sender == UsersController.logged_user.username) || (p.Receiver == UsersController.logged_user.username && p.Sender == temp_contact)
                                                  select p;
                var temp3 = new List <Message>(await convQuery3.Distinct().ToListAsync());

                foreach (var item in temp3)
                {
                    if (item.Sender == UsersController.logged_user.username)
                    {
                        conv_model.messages.Add(new Text(item.Text, "sent", item.Date_created));
                    }
                    else
                    {
                        conv_model.messages.Add(new Text(item.Text, "received", item.Date_created));
                    }
                }
            }

            if (!string.IsNullOrEmpty(message_text)) //publish message
            {
                conv_model.send_channel = temp_contact;
                Message message_send = new Message(last_id + 1, UsersController.logged_user.username, temp_contact, DateTime.Now, message_text);
                try
                {
                    conv_model.messages.Add(new Text(message_send.Text, "sent", message_send.Date_created));
                    var result = await pusher.TriggerAsync(
                        conv_model.send_channel,
                        "my-event",
                        new { message = message_text });

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

                    ModelState.Clear();
                    last_id += 1;
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            if (!string.IsNullOrEmpty(new_received) && !string.IsNullOrEmpty(contact_received)) //receive message
            {
                last_id = last_id + 1;
                Message message_receive = new Message(last_id + 1, contact_received, UsersController.logged_user.username, DateTime.Now, new_received);
                conv_model.messages.Add(new Text(message_receive.Text, "received", message_receive.Date_created));
                conv_model.new_received = new_received;
                _context.Add(message_receive);
                await _context.SaveChangesAsync();

                // ModelState.Clear();
                return(View(conv_model));
            }
            return(View(conv_model));
        }
Ejemplo n.º 6
0
        public void BackPropagation(float b0_t0, float b1_t0, float w0_0_t0, float w0_1_t0, float w0_2_t0, float w0_3_t0, float w1_1_t0, float actual_price, string location, MyPlannerContext _context, int weights_id, int weights_location_id, MyTask.TagType tag)
        {
            float suggested_price = this.SuggestedPrice(b0_t0, b1_t0, w0_0_t0, w0_1_t0, w0_2_t0, w0_3_t0, w1_1_t0);
            float b0_t1           = b0_t0;   //updated biases
            float b1_t1           = b1_t0;
            float w0_0_t1         = w0_0_t0; //updated weights;
            float w0_1_t1         = w0_1_t0;
            float w0_2_t1         = w0_2_t0;
            float w0_3_t1         = w0_3_t0;
            float w1_1_t1         = w1_1_t0;
            int   n = 0;
            float temp_correction_b0 = 0;

            actual_price = actual_price / Duration;
            //Derivative of cost with respect to weights for second layer
            if (w1_1_t0 * a1 + b1_t0 > 0)
            {
                w1_1_t1 -= (learning_rate * 2 * (w1_1_t0 * a1 + b1_t0 - actual_price) * a1);
            }
            // Derivative of cost with respect to biases for second layer
            if (w1_1_t0 * a1 + b1_t0 > 0)
            {
                b1_t1 -= (learning_rate * 2 * (w1_1_t0 * a1 + b1_t0 - actual_price));
            }
            //Derivative of cost with respect to weights for first layer
            if (w0_0_t0 * x1 + b0_t0 > 0)
            {
                float correction = (learning_rate * 2 * (w0_0_t0 * x0 + b0_t0 - ((actual_price - b1_t0) / w1_1_t0) * x0 * w1_1_t0));
                w0_0_t1 -= correction;
            }

            if (w0_1_t0 * x1 + b0_t0 > 0)
            {
                float correction = (learning_rate * 2 * ((w0_1_t0 * x1 + b0_t0 - (actual_price - b1_t0) / w1_1_t0) * x1 * w1_1_t0));
                w0_1_t1 -= correction;
            }

            if (w0_2_t0 * x2 + b0_t0 > 0)
            {
                float correction = (learning_rate * 2 * ((w0_2_t0 * x2 + b0_t0 - (actual_price - b1_t0) / w1_1_t0) * x2 * w1_1_t0));
                w0_2_t1 -= correction;
            }

            if (w0_3_t0 * x3 + b0_t0 > 0)
            {
                float correction = (learning_rate * 2 * ((w0_3_t0 * x3 + b0_t0 - (actual_price - b1_t0) / w1_1_t0) * x3 * w1_1_t0));
                w0_3_t1 -= correction;
            }

            // Derivative of cost with respect to biases for first layer
            if (w0_0_t0 * x0 + b0_t0 > 0)
            {
                temp_correction_b0 -= (learning_rate * 2 * (w0_0_t0 * x1 + b0_t0 - (actual_price - b1_t0) / w1_1_t0));
                n += 1;
            }
            if (w0_1_t0 * x1 + b0_t0 > 0)
            {
                temp_correction_b0 -= (learning_rate * 2 * (w0_1_t0 * x1 + b0_t0 - (actual_price - b1_t0) / w1_1_t0));
                n += 1;
            }
            if (w0_2_t0 * x2 + b0_t0 > 0)
            {
                temp_correction_b0 -= (learning_rate * 2 * (w0_2_t0 * x2 + b0_t0 - (actual_price - b1_t0) / w1_1_t0));
                n += 1;
            }
            if (w0_3_t0 * x3 + b0_t0 > 0)
            {
                temp_correction_b0 -= (learning_rate * 2 * (w0_3_t0 * x3 + b0_t0 - (actual_price - b1_t0) / w1_1_t0));
                n += 1;
            }
            b0_t1 += temp_correction_b0 / n;

            Weights         weights_t1          = new Weights(weights_id + 1, w0_0_t1, w0_1_t1, w0_2_t1, w0_3_t1, b0_t1, tag);
            LocationWeights location_weights_t1 = new LocationWeights(weights_location_id + 1, w1_1_t1, b1_t1, location, tag);

            _context.Add(weights_t1);
            _context.Add(location_weights_t1);
        }