Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "EntryId,Prompt,Title,Text")] Entry entry)
        {
            if (ModelState.IsValid)
            {
                db.Entries.Add(entry);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(entry));
        }
        public bool DealMessage501(bool isReceived, bool isCreated, string guid, string orderNoFake, string logisticNo, string destPath)
        {
            bool success = true;

            try
            {
                EntryCreate entry = new EntryCreate();
                entry.ItemGuid    = new Guid(guid);
                entry.IsReceived  = isReceived;
                entry.IsCreated   = isCreated;
                entry.ReceiveTime = entry.CreateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                entry.FilePath    = destPath;
                using (var db = new EntryContext())
                {
                    var query = from m in db.MessageTracks.Include("Entry501s")
                                where m.OrderNoFake == orderNoFake
                                select m;
                    var msTrack = query.FirstOrDefault();
                    msTrack.Entry501s.Add(entry);
                    msTrack.LastUpdateTicks = DateTime.Now.Ticks;
                    msTrack.Schedule        = 501;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logs.Error(string.Format("DealMessage501 OrderNoFake: {0} , Exception: {1}", orderNoFake, ex.ToString()));
                success = false;
            }
            return(success);
        }
        public bool DealMessage504(string logisticsNo, string guid, string status, string logisticsStatus, string returnTime, string returnInfo, string destPath)
        {
            bool success = true;

            try
            {
                EntryReceive entry = new EntryReceive();
                entry.ItemGuid   = new Guid(guid);
                entry.Status     = Convert.ToInt32(status);
                entry.ReturnTime = returnTime;
                entry.ReturnInfo = returnInfo;
                entry.FilePath   = destPath;
                entry.Commnet1   = logisticsStatus;
                using (var db = new EntryContext())
                {
                    var query = from m in db.MessageTracks.Include("Entry504s")
                                where m.LogisticsNo == logisticsNo
                                select m;
                    var msTrack = query.FirstOrDefault();
                    msTrack.Entry504s.Add(entry);
                    msTrack.LastUpdateTicks = DateTime.Now.Ticks;
                    msTrack.Schedule        = 504;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logs.Error(string.Format("DealMessage504 LogisticsNo: {0} Exception: {1}", logisticsNo, ex.ToString()));
                success = false;
            }
            return(success);
        }
        public bool DealMessage302(string orderNoFake, string guid, string status, string returnTime, string returnInfo, string destPath)
        {
            bool success = true;

            try
            {
                EntryReceive entry = new EntryReceive();
                entry.ItemGuid   = new Guid(guid);
                entry.Status     = Convert.ToInt32(status);
                entry.ReturnTime = returnTime;
                entry.ReturnInfo = returnInfo;
                entry.FilePath   = destPath;
                using (var db = new EntryContext())
                {
                    var query = from m in db.MessageTracks.Include("Entry302s")
                                where m.OrderNoFake == orderNoFake
                                select m;
                    var msTrack = query.FirstOrDefault();
                    msTrack.Entry302s.Add(entry);
                    msTrack.LastUpdateTicks = DateTime.Now.Ticks;
                    if (msTrack.Schedule < 302)
                    {
                        msTrack.Schedule = 302;
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logs.Error(string.Format("DealMessage302 OrderNoFake: {0} , Exception: {1}", orderNoFake, ex.ToString()));
                success = false;
            }
            return(success);
        }
        public bool DeleteMessageByFilter(MessageFilter filter)
        {
            bool success = true;

            try
            {
                using (var db = new EntryContext())
                {
                    var query = from m in db.MessageTracks
                                .Include("Entry301s")
                                .Include("Entry302s")
                                .Include("Entry501s")
                                .Include("Entry502s")
                                .Include("Entry503s")
                                .Include("Entry504s")
                                .Include("Entry601s")
                                .Include("Entry602s")
                                where (string.IsNullOrEmpty(filter.OrderNo) ? true : m.OrderNo.IndexOf(filter.OrderNo) >= 0) &&
                                (string.IsNullOrEmpty(filter.LogisticsNo) ? true : m.LogisticsNo.IndexOf(filter.LogisticsNo) >= 0) &&
                                (filter.Status.Equals("All") ? true : filter.Status.Equals("True") ? m.IsFinished : !m.IsFinished) &&
                                (filter.Start.Ticks == 0 ? true : m.LastUpdateTicks >= filter.Start.Ticks) &&
                                (filter.End.Ticks == 0 ? true : m.LastUpdateTicks <= filter.End.Ticks)
                                select m;
                    db.MessageTracks.RemoveRange(query);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logs.Error("DeleteMessageByFilter Exception: " + ex.ToString());
                success = false;
            }
            return(success);
        }
Exemplo n.º 6
0
        // Changes property IsArchived on given entry and it's child entries if there are any.
        public static ActionResult <string> ChangeArchivedEntryByID(int id)
        {
            Entry entryToBeChanged             = GetEntryByID(id);
            List <Allergen_Entry> childEntries = new List <Allergen_Entry>();

            if (entryToBeChanged == null)
            {
                throw new Exception("Entry wasn't found.");
            }

            using (EntryContext context = new EntryContext())
            {
                entryToBeChanged            = context.Entries.Where(x => x.ID == id).SingleOrDefault();
                entryToBeChanged.IsArchived = !entryToBeChanged.IsArchived;

                childEntries = context.Allergen_Entries.Where(x => x.EntryID == id).ToList();
                if (childEntries.Count > 0)
                {
                    foreach (Allergen_Entry childEntry in childEntries)
                    {
                        childEntry.IsArchived = !childEntry.IsArchived;
                    }
                }
                context.SaveChanges();
            }

            return("Success!");
        }
        public bool DeleteMessageByGuid(MessageFilter filter)
        {
            bool success = true;

            try
            {
                using (var db = new EntryContext())
                {
                    var query = from m in db.MessageTracks
                                .Include("Entry301s")
                                .Include("Entry302s")
                                .Include("Entry501s")
                                .Include("Entry502s")
                                .Include("Entry503s")
                                .Include("Entry504s")
                                .Include("Entry601s")
                                .Include("Entry602s")
                                where m.ItemGuid == filter.Guid
                                select m;
                    db.Entry(query.FirstOrDefault()).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logs.Error("DeleteMessageByGuid Exception: " + ex.ToString());
                success = false;
            }
            return(success);
        }
Exemplo n.º 8
0
        // Sanitizes input, creates new user profile
        public static ActionResult <string> RegisterUser(string id, string username, string password, bool isDiabetic)
        {
            if (id.Length < 36)
            {
                throw new Exception("Invalid ID.");
            }
            else if (GetUserByID(id) != null)
            {
                throw new Exception("ID already exists in the database.");
            }
            else if (GetUserByName(username) != null)
            {
                throw new Exception("Username already exists in the database.");
            }
            else if (!TestString(username))
            {
                throw new Exception("Username contains forbidden characters.");
            }
            else if (!TestString(password))
            {
                throw new Exception("Password contains forbidden characters.");
            }

            using (EntryContext context = new EntryContext())
            {
                password = GetHash(username + password);
                User newUser = new User(id, username, password, isDiabetic);
                context.Users.Add(newUser);

                context.SaveChanges();
            }
            return("Success!");
        }
Exemplo n.º 9
0
        //TODO список категорий и именно его закидывать уже куда надо List<string> category = new List<string>() { "Квартиры", "Телефоны", "Животные", "Машины" };

        //-SETTINGS/ADMIN BLOCK--------------------------------------------------------------------------------------------------------------------//

        public ActionResult Index()
        {
            db.Entries.RemoveRange(db.Entries.Where(x1 => x1.Header.IndexOf("test322") != -1).ToList());
            db.Entries.RemoveRange(db.Entries.Where(x1 => x1.Id == 7378).ToList());
            db.SaveChanges();
            return(View());
        }
Exemplo n.º 10
0
        public IActionResult Create(Entry entry)
        {
            if (entry == null)
            {
                return(NoContent());
            }

            _context.Add(entry);
            _context.SaveChanges();

            return(Ok());
        }
Exemplo n.º 11
0
        public IActionResult Create(Device device)
        {
            if (device == null)
            {
                return(NoContent());
            }

            Device alreadyExistingDevice = _context.Devices.ToList().Find(x => x.Name == device.Name);

            if (alreadyExistingDevice != null)
            {
                return(Json(alreadyExistingDevice.Id));
            }

            _context.Update(device);
            _context.SaveChanges();

            return(Json(device.Id));
        }
        public bool DealMessage301(string orderNo, string orderNoFake, string logisticsNo, bool isReceived, bool isCreated, string guid, string destPath, string logisticCode)
        {
            bool success = true;

            try
            {
                EntryCreate entry = new EntryCreate();
                entry.ItemGuid   = new Guid(guid);
                entry.IsReceived = isReceived;
                entry.IsCreated  = isCreated;
                entry.CreateTime = entry.ReceiveTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                entry.FilePath   = destPath;

                MessageTrack msTrack = new MessageTrack();
                msTrack.ItemGuid        = Guid.NewGuid();
                msTrack.OrderNo         = orderNo;
                msTrack.OrderNoFake     = orderNoFake;
                msTrack.LogisticsNo     = logisticsNo;
                msTrack.Schedule        = 301;
                msTrack.LastUpdateTicks = DateTime.Now.Ticks;
                msTrack.Commnet1        = logisticCode;
                msTrack.Entry301s       = new List <EntryCreate>();
                msTrack.Entry302s       = new List <EntryReceive>();
                msTrack.Entry501s       = new List <EntryCreate>();
                msTrack.Entry502s       = new List <EntryReceive>();
                msTrack.Entry503s       = new List <EntryCreate>();
                msTrack.Entry504s       = new List <EntryReceive>();
                msTrack.Entry601s       = new List <EntryCreate>();
                msTrack.Entry602s       = new List <EntryReceive>();
                msTrack.Entry301s.Add(entry);
                using (var db = new EntryContext())
                {
                    db.MessageTracks.Add(msTrack);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logs.Error(string.Format("DealMessage301 OrderNo: {0} , Exception: {1}", orderNo, ex.ToString()));
                success = false;
            }
            return(success);
        }
Exemplo n.º 13
0
        public void CreatesSampleData()
        {
            return;

            EntryContext context = new EntryContext();

            Random random = new Random();

            for (int i = 0; i < 300; i++)
            {
                Entry entry = new Entry()
                {
                    Value = (100 * random.NextDouble()) * (random.NextDouble() > 0.5 ? -1 : 1), CreatedDateTime = DateTime.Now.AddHours(-i * 12)
                };

                context.Entries.Add(entry);
            }

            context.SaveChanges();
        }
Exemplo n.º 14
0
        // Edits notes of a given entry
        public static string ChangeEntryNotesByID(int id, string notes)
        {
            Entry entryToBeChanged = GetEntryByID(id);

            if (entryToBeChanged == null)
            {
                throw new Exception("Entry wasn't found.");
            }
            else if (!TestString(notes))
            {
                throw new Exception("Notes contain invalid characters.");
            }

            using (EntryContext context = new EntryContext())
            {
                entryToBeChanged = context.Entries.Where(x => x.ID == id).SingleOrDefault();

                entryToBeChanged.Notes = notes;

                context.SaveChanges();
            }

            return("Success!");
        }
Exemplo n.º 15
0
        // Sanitizes input, creates new notebook Entry and Allergen-Entry if allergens were entered.
        public static ActionResult <string> MakeEntry(int categoryID, string userID, int statusID, DateTime time, int carbs, int protein, int fats, string notes, double insulin, double bg, int allergen1, int allergen2, int allergen3, int exerciseLength)
        {
            if (notes != null)
            {
                if (!TestString(notes))
                {
                    throw new Exception("Notes contain invalid characters.");
                }
            }

            if (allergen1 != 0)
            {
                if (GetAllergenByID(allergen1) == null)
                {
                    throw new Exception("Passed allergen 1 doesn't exist.");
                }
            }
            if (allergen2 != 0)
            {
                if (GetAllergenByID(allergen2) == null)
                {
                    throw new Exception("Passed allergen 2 doesn't exist.");
                }
            }
            if (allergen3 != 0)
            {
                if (GetAllergenByID(allergen3) == null)
                {
                    throw new Exception("Passed allergen 3 doesn't exist.");
                }
            }

            if (GetCategoryByID(categoryID) == null)
            {
                throw new Exception("Category doesn't exist.");
            }
            else if (GetStatusByID(statusID) == null)
            {
                throw new Exception("Status doesn't exist.");
            }
            else if (carbs > 9999 || carbs < 0 || protein > 9999 || protein < 0 || fats > 9999 || fats < 0)
            {
                throw new Exception("Nutrition information values are out of range.");
            }
            else if (insulin < 0 || insulin > 999 || bg < 0 || bg > 999)
            {
                throw new Exception("Diabetic data is out of range.");
            }
            else if (userID.Length != 36)
            {
                throw new Exception("User ID is invalid.");
            }
            else if (GetUserByID(userID) == null)
            {
                throw new Exception("User doesn't exist in the database.");
            }
            else if (exerciseLength < 0 || exerciseLength > 999)
            {
                throw new Exception("Exercise length is invalid.");
            }

            using (EntryContext context = new EntryContext())
            {
                Entry newEntry = new Entry(categoryID, userID, statusID, time, carbs, protein, fats, notes, insulin, bg, exerciseLength);
                context.Entries.Add(newEntry);
                context.SaveChanges();

                if (allergen1 != 0)
                {
                    context.Allergen_Entries.Add(
                        new Allergen_Entry()
                    {
                        AllergenID = allergen1,
                        EntryID    = newEntry.ID
                    }

                        );
                }

                if (allergen2 != 0)
                {
                    context.Allergen_Entries.Add(
                        new Allergen_Entry()
                    {
                        AllergenID = allergen2,
                        EntryID    = newEntry.ID
                    }

                        );
                }

                if (allergen3 != 0)
                {
                    context.Allergen_Entries.Add(
                        new Allergen_Entry()
                    {
                        AllergenID = allergen3,
                        EntryID    = newEntry.ID
                    }

                        );
                }

                context.SaveChanges();
            }

            return("Success!");
        }