Пример #1
0
        public async Task <JsonResult> ReminderUpdate(Guid id, DateTime timestamp, string description, int status)
        {
            var user_login = await db.User.Where(x => x.UserName == User.Identity.Name).FirstOrDefaultAsync();

            RemindersModels remindersModels = await db.Reminders.FindAsync(id);

            //remindersModels.Timestamp = new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, DateTime.UtcNow.Second);
            //remindersModels.Description = description;
            remindersModels.Status_enumid   = (RemindersStatusEnum)status;
            db.Entry(remindersModels).State = EntityState.Modified;

            string desc_log = "";

            if (remindersModels.Status_enumid == RemindersStatusEnum.New)
            {
                desc_log = "[New] " + description;
            }
            else if (remindersModels.Status_enumid == RemindersStatusEnum.InProgress)
            {
                desc_log = "[In Progress] " + description;
            }
            else if (remindersModels.Status_enumid == RemindersStatusEnum.OnHold)
            {
                desc_log = "[On Hold] " + description;
            }
            else if (remindersModels.Status_enumid == RemindersStatusEnum.Waiting)
            {
                desc_log = "[Waiting] " + description;
            }
            else if (remindersModels.Status_enumid == RemindersStatusEnum.Completed)
            {
                desc_log = "[Completed] " + description;
            }
            else if (remindersModels.Status_enumid == RemindersStatusEnum.Cancel)
            {
                desc_log = "[Cancel] " + description;
            }

            ActivityLogsModels activityLogsModels = new ActivityLogsModels
            {
                Id              = Guid.NewGuid(),
                Timestamp       = DateTime.UtcNow,
                TableName       = "Reminders",
                RefId           = remindersModels.Id,
                Description     = desc_log,
                UserAccounts_Id = user_login.Id
            };

            db.ActivityLogs.Add(activityLogsModels);

            await db.SaveChangesAsync();

            return(Json(new { status = "200" }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public async Task <JsonResult> ReminderAdd(DateTime timestamp, string description)
        {
            var user_login = await db.User.Where(x => x.UserName == User.Identity.Name).FirstOrDefaultAsync();

            RemindersModels remindersModels = new RemindersModels
            {
                Id            = Guid.NewGuid(),
                Branches_Id   = user_login.Branches_Id,
                Timestamp     = new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, DateTime.UtcNow.Second),
                Description   = description,
                Status_enumid = RemindersStatusEnum.New
            };

            string   status;
            DateTime dateEnd       = new DateTime(timestamp.Year, timestamp.Month, timestamp.Day, DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, DateTime.UtcNow.Second);
            DateTime dateStart     = dateEnd.AddSeconds(-10); //range time = 10 seconds
            var      reminderCheck = await db.Reminders.Where(x => x.Branches_Id == remindersModels.Branches_Id &&
                                                              x.Timestamp >= dateStart && x.Timestamp <= dateEnd &&
                                                              x.Description == remindersModels.Description &&
                                                              x.Status_enumid == remindersModels.Status_enumid
                                                              ).FirstOrDefaultAsync();

            if (reminderCheck != null)
            {
                status = "300";
            }
            else
            {
                status = "200";
                db.Reminders.Add(remindersModels);

                ActivityLogsModels activityLogsModels = new ActivityLogsModels
                {
                    Id              = Guid.NewGuid(),
                    Timestamp       = DateTime.UtcNow,
                    TableName       = "Reminders",
                    RefId           = remindersModels.Id,
                    Description     = "[New] " + description,
                    UserAccounts_Id = user_login.Id
                };
                db.ActivityLogs.Add(activityLogsModels);

                await db.SaveChangesAsync();
            }

            return(Json(new { status }, JsonRequestBehavior.AllowGet));
        }