예제 #1
0
        public ActionResult Edit(int id)
        {
            EditViewModel editAddViewModel = new EditViewModel();
            ThingsDone    thing            = _se.ThingsDones.FirstOrDefault(m => m.index == id);

            editAddViewModel.Index   = thing.index;
            editAddViewModel.Action  = thing.Action;
            editAddViewModel.Actions = thing.Actions;
            //if(thing.EndTime == null && (thing.Actions.Title.IndexOf("Feed", System.StringComparison.CurrentCultureIgnoreCase) >=0
            //|| thing.Actions.Title.IndexOf("BF", System.StringComparison.CurrentCultureIgnoreCase) >=0))
            //{
            //    editAddViewModel.EndTime = DateTime.Now.AddMinutes(30);
            //}
            //if (thing.EndTime == null && thing.Actions.Title.IndexOf("Sleep", System.StringComparison.CurrentCultureIgnoreCase) >= 0)
            //{
            //    editAddViewModel.EndTime = DateTime.Now;
            //}
            if (thing.EndTime != null)
            {
                editAddViewModel.EndTime = thing.EndTime;
            }
            editAddViewModel.StartTime  = thing.StartTime;
            editAddViewModel.OZ         = thing.OZ;
            editAddViewModel.Mood       = thing.Mood;
            editAddViewModel.Notes      = thing.Notes;
            editAddViewModel.LiquidType = thing.LiquidSizeID;
            editAddViewModel.Kid        = thing.BabyNameID.Value;


            return(View(editAddViewModel));
        }
예제 #2
0
        public ActionResult Add(AddViewModel addViewModel, FormCollection form)
        {
            List <Actions> tempActions = null;


            var Actions     = form["Action"].Split(',');
            var LiquidTypes = form["POS"].Split(','); //Fucken MS bad coding, this value is "LiquidType"
            var OZs         = form["OZ"].Replace(" ", "").Split(',');
            var babynames   = form["KidName"].Split(',');


            //if (Actions.Count() > 1)
            //    tempActions = _se.Actions1.Where(m => m.Delete == false).ToList();

            string firstaction   = Actions[0];
            int?   fenLinqAction = _se.Actions1.FirstOrDefault(m => m.Title == firstaction)?.index;

            if (fenLinqAction == null)
            {
                Actions tempavm = _se.Actions1.Add(new Actions {
                    Title = firstaction
                });
                _se.SaveChanges();
                fenLinqAction = tempavm.index;
            }

            DateTime againfenLinqStartTime = Convert.ToDateTime(FixFuckenDate(addViewModel.StartTime));

            if (!addViewModel.EndTime.IsNullOrWhiteSpace())
            {
                if (FixFuckenDate(addViewModel.StartTime) > FixFuckenDate(addViewModel.EndTime))
                {
                    addViewModel.EndTime = null;
                }
            }


            var doubleEntry = _se.ThingsDones.FirstOrDefault(m => m.Action == fenLinqAction && m.StartTime == againfenLinqStartTime);

            if (!ModelState.IsValid)
            {
                return(View(addViewModel));
            }

            if (doubleEntry == null)
            {
                ThingsDone td;

                for (int i = 0; i < Actions.Count(); i++)
                {
                    td = new ThingsDone();

                    string currentactionname = Actions[i];

                    fenLinqAction = _se.Actions1.FirstOrDefault(m => m.Title == currentactionname)?.index;

                    if (fenLinqAction == null)
                    {
                        Actions tempavm = _se.Actions1.Add(new Actions {
                            Title = currentactionname
                        });
                        _se.SaveChanges();
                        fenLinqAction = tempavm.index;
                    }

                    td.Action = Convert.ToInt32(fenLinqAction);

                    td.BabyNameID = Convert.ToInt16(babynames[i]);

                    td.StartTime = againfenLinqStartTime;

                    if (addViewModel.EndTime != null)
                    {
                        td.EndTime = Convert.ToDateTime(FixFuckenDate(addViewModel.EndTime));
                    }

                    if (!OZs[i].Length.Equals(0))
                    {
                        td.OZ = Convert.ToDouble(OZs[i]); //might need to check for null
                    }
                    if (i == 0)
                    {
                        td.Notes     = addViewModel.Notes;
                        td.Latitude  = addViewModel.Latitude;
                        td.Longitude = addViewModel.Longitude;
                    }


                    td.LiquidSizeID = Convert.ToInt16(LiquidTypes[i]); //might need to check for null


                    _se.ThingsDones.Add(td);
                }
            }

            _se.SaveChanges();
            return(RedirectToAction("Index", "DoneThings"));
        }