예제 #1
0
 public ActionResult Edit(MessageEditViewModel model)
 {
     using (AlexaSkillEntities db = new AlexaSkillEntities())
     {
         if (model.MessageId != 0)
         {
             IntentMessage message = db.IntentMessages.FirstOrDefault(x => x.Id == model.MessageId);
             if (message != null)
             {
                 message.Message = model.Message;
             }
         }
         else
         {
             IntentMessage message = new IntentMessage()
             {
                 Message  = model.Message,
                 IntentId = model.IntentId
             };
             db.IntentMessages.Add(message);
         }
         db.SaveChanges();
     }
     return(RedirectToAction("Detail", "Intent", new { id = model.IntentId }));
 }
 public ActionResult Edit(WelcomeMessageEditViewModel model)
 {
     using (AlexaSkillEntities db = new AlexaSkillEntities())
     {
         if (model.MessageId != 0)
         {
             WelcomeMessage message = db.WelcomeMessages.FirstOrDefault(x => x.Id == model.MessageId);
             if (message != null)
             {
                 message.Message = model.Message;
             }
         }
         else
         {
             WelcomeMessage message = new WelcomeMessage()
             {
                 Message = model.Message,
                 SkillId = model.SkillId
             };
             db.WelcomeMessages.Add(message);
         }
         db.SaveChanges();
     }
     return(RedirectToAction("WelcomeMessages", "Skill", new { id = model.SkillId }));
 }
        public ActionResult EditAnswer(AnswerEditViewModel model)
        {
            Answer answer = new Answer();

            using (AlexaSkillEntities db = new AlexaSkillEntities())
            {
                if (model.AnswereId != null && model.AnswereId != 0)
                {
                    answer = db.Answers.FirstOrDefault(x => x.Id == model.AnswereId);
                }

                if (db.Answers.Where(x => x.Answert == model.Answer && x.Id != model.AnswereId).Count() > 0)
                {
                    return(RedirectToAction("Overview", "CoreTemperature", new { skillId = model.SkillId }));
                }

                if (answer != null)
                {
                    answer.Answert          = model.Answer;
                    answer.SessionTerm      = model.SessionTerm;
                    answer.ShouldEndSession = model.ShouldEndSession;

                    if (model.AnswereId == null || model.AnswereId == 0)
                    {
                        db.Answers.Add(answer);
                    }
                }
                db.SaveChanges();
            }
            return(RedirectToAction("AnswerOverview", "CoreTemperature", new { skillId = model.SkillId }));
        }
        public ActionResult EditAnswerCalls(int skillId, int answerId)
        {
            AnswerCallViewModel model = new AnswerCallViewModel()
            {
                SkillId  = skillId,
                AnswerId = answerId
            };

            using (AlexaSkillEntities db = new AlexaSkillEntities())
            {
                if (answerId != 0)
                {
                    Answer answer = db.Answers.FirstOrDefault(x => x.Id == answerId);
                    if (answer != null)
                    {
                        model.Answer = answer.Answert;
                    }
                }
                List <Meat> meats = db.Meats.Where(x => x.AnswerId == answerId).ToList();

                foreach (Meat meat in meats)
                {
                    model.Calls.Add(new AnswerCallItemViewModel()
                    {
                        Id   = meat.Id,
                        Name = meat.Name
                    });
                }
                db.SaveChanges();
            }

            return(View(model));
        }
        public ActionResult EditTemperatureCalls(int skillId, int temperatureId)
        {
            TemperatureCallViewModel model = new TemperatureCallViewModel()
            {
                SkillId       = skillId,
                TemperatureId = temperatureId
            };

            using (AlexaSkillEntities db = new AlexaSkillEntities())
            {
                if (temperatureId != 0)
                {
                    CoreTemperature temperature = db.CoreTemperatures.FirstOrDefault(x => x.Id == temperatureId);
                    if (temperature != null)
                    {
                        model.TemperatureName = temperature.Name;
                    }
                }
                List <Meat> meats = db.Meats.Where(x => x.CoreTemperatureId == temperatureId).ToList();

                foreach (Meat meat in meats)
                {
                    model.Calls.Add(new TemperatureCallItemViewModel()
                    {
                        Id   = meat.Id,
                        Name = meat.Name
                    });
                }
                db.SaveChanges();
            }

            return(View(model));
        }
예제 #6
0
 public ActionResult Edit(IntentCallEditViewModel model)
 {
     using (AlexaSkillEntities db = new AlexaSkillEntities())
     {
         if (model.IntentCallId != 0)
         {
             IntentCall message = db.IntentCalls.FirstOrDefault(x => x.Id == model.IntentCallId);
             if (message != null)
             {
                 message.CallText = model.CallText;
             }
         }
         else
         {
             IntentCall intentCall = new IntentCall()
             {
                 CallText = model.CallText,
                 IntentId = model.IntentId
             };
             db.IntentCalls.Add(intentCall);
         }
         db.SaveChanges();
     }
     return(RedirectToAction("Detail", "Intent", new { id = model.IntentId }));
 }
        public ActionResult UserCallEdit(UserCallEditViewModel model)
        {
            using (AlexaSkillEntities db = new AlexaSkillEntities())
            {
                Meat meat = new Meat();
                if (model.UserCallId != 0)
                {
                    meat = db.Meats.FirstOrDefault(x => x.Id == model.UserCallId);
                }
                if (meat == null)
                {
                    meat = new Meat();
                }
                meat.Name              = model.UserCallName;
                meat.AnswerId          = model.AnswerId;
                meat.CoreTemperatureId = model.CoreTemperatureId;
                if (meat.Id == 0)
                {
                    db.Meats.Add(meat);
                }
                db.SaveChanges();
            }

            return(RedirectToAction("UserCallOverview", new { skillId = model.SkillId }));
        }
예제 #8
0
        public ActionResult Delete(int id)
        {
            IntentCallEditViewModel model = new IntentCallEditViewModel();

            using (AlexaSkillEntities db = new AlexaSkillEntities())
            {
                IntentCall intentCall = db.IntentCalls.FirstOrDefault(x => x.Id == id);
                db.IntentCalls.Remove(intentCall);
                db.SaveChanges();
                return(RedirectToAction("Detail", "Intent", new { id = intentCall.IntentId }));
            }
        }
예제 #9
0
        public ActionResult Delete(int id)
        {
            MessageEditViewModel model = new MessageEditViewModel();

            using (AlexaSkillEntities db = new AlexaSkillEntities())
            {
                IntentMessage             message = db.IntentMessages.FirstOrDefault(x => x.Id == id);
                List <IntentMessagesRead> reads   = db.IntentMessagesReads.Where(x => x.IntentMessageId == id).ToList();
                db.IntentMessagesReads.RemoveRange(reads);
                db.IntentMessages.Remove(message);
                db.SaveChanges();
                return(RedirectToAction("Detail", "Intent", new { id = message.IntentId }));
            }
        }
        public ActionResult UserCallDelete(int skillId, int userCallId)
        {
            using (AlexaSkillEntities db = new AlexaSkillEntities())
            {
                Meat meat = db.Meats.FirstOrDefault(x => x.Id == userCallId);
                if (meat != null)
                {
                    db.Meats.Remove(meat);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("UserCallOverview", new { skillId = skillId }));
        }
예제 #11
0
 public ActionResult Edit(IntentEditViewModel model)
 {
     using (AlexaSkillEntities db = new AlexaSkillEntities())
     {
         Intent intent = db.Intents.FirstOrDefault(x => x.Id == model.IntentId);
         if (intent != null)
         {
             intent.Name             = model.Name;
             intent.ShouldEndSession = model.ShouldEndSession;
         }
         db.SaveChanges();
         return(RedirectToAction("Intents", "Skill", new { id = intent.SkillId }));
     }
 }
예제 #12
0
 public ActionResult Add(IntentAddViewModel model)
 {
     using (AlexaSkillEntities db = new AlexaSkillEntities())
     {
         Intent intent = new Intent()
         {
             SkillId          = model.SkillId,
             Name             = model.Name.Replace(" ", ""),
             ShouldEndSession = model.ShouldEndSession
         };
         db.Intents.Add(intent);
         db.SaveChanges();
         return(RedirectToAction("Detail", "Intent", new { id = intent.Id }));
     }
 }
예제 #13
0
 private void LogRequestToDb(AlexaRequestType requestType, string applicationId, string userId, string intent, string intentParam, string resultMessage)
 {
     using (AlexaSkillEntities db = new AlexaSkillEntities())
     {
         db.RequestLogs.Add(new RequestLog()
         {
             RequestTime   = DateTime.Now,
             ApplicationId = applicationId,
             UserId        = userId,
             RequestType   = requestType.ToString(),
             Intent        = intent,
             IntentParam   = intentParam,
             Information   = resultMessage
         });
         db.SaveChanges();
     }
 }
        public ActionResult EditAnswerCalls(AnswerCallViewModel model)
        {
            using (AlexaSkillEntities db = new AlexaSkillEntities())
            {
                if (db.Meats.Where(x => x.Name == model.AddCallName).Count() > 0)
                {
                    return(RedirectToAction("EditAnswerCalls", "CoreTemperature", new { skillId = model.SkillId, answerId = model.AnswerId }));
                }

                Meat meat = new Meat()
                {
                    Name     = model.AddCallName,
                    AnswerId = model.AnswerId
                };
                db.Meats.Add(meat);
                db.SaveChanges();
            }

            return(RedirectToAction("EditAnswerCalls", "CoreTemperature", new { skillId = model.SkillId, answerId = model.AnswerId }));
        }
        public ActionResult EditTemperature(TemperatureEditViewModel model)
        {
            CoreTemperature temperature = new CoreTemperature();

            using (AlexaSkillEntities db = new AlexaSkillEntities())
            {
                if (model.TemperatureId != null && model.TemperatureId != 0)
                {
                    temperature = db.CoreTemperatures.FirstOrDefault(x => x.Id == model.TemperatureId);
                }

                if (db.CoreTemperatures.Where(x => x.Name == model.Name && x.Id != model.TemperatureId).Count() > 0)
                {
                    return(RedirectToAction("Overview", "CoreTemperature", new { skillId = model.SkillId }));
                }

                if (temperature != null)
                {
                    temperature.Name             = model.Name;
                    temperature.DefaultDegree    = model.DefaultDegree;
                    temperature.DefaultMaxDegree = model.DefaultMaxDegree;
                    temperature.DefaultMinDegree = model.DefaultMinDegree;
                    temperature.DoneDegree       = model.DoneDegree;
                    temperature.DoneMaxDegree    = model.DoneMaxDegree;
                    temperature.DoneMinDegree    = model.DoneMinDegree;
                    temperature.MediumDegree     = model.MediumDegree;
                    temperature.MediumMaxDegree  = model.MediumMaxDegree;
                    temperature.MediumMinDegree  = model.MediumMinDegree;
                    temperature.RareDegree       = model.RareDegree;
                    temperature.RareMaxDegree    = model.RareMaxDegree;
                    temperature.RareMinDegree    = model.RareMinDegree;

                    if (model.TemperatureId == null || model.TemperatureId == 0)
                    {
                        db.CoreTemperatures.Add(temperature);
                    }
                }
                db.SaveChanges();
            }
            return(RedirectToAction("Overview", "CoreTemperature", new { skillId = model.SkillId }));
        }
예제 #16
0
        public ActionResult Add(SkillAddViewModel model)
        {
            string userId = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                using (AlexaSkillEntities db = new AlexaSkillEntities())
                {
                    db.Skills.Add(new Context.Skill()
                    {
                        ApplicationID = model.ApplicationID,
                        Name          = model.Name,
                        UserId        = userId,
                        SkillType     = model.SkillTypeId
                    });
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
            }
            model.SkillTypes = SkillList();
            return(View(model));
        }
        public IntentMessageModel GetIntentMessage(string applicationId, string intentName, string userId)
        {
            int           skillId    = GetSkillId(applicationId);
            IntentMessage newMessage = null;

            using (var db = new AlexaSkillEntities())
            {
                Intent intent = db.Intents.FirstOrDefault(x => x.Name == intentName && x.SkillId == skillId);
                if (intent != null)
                {
                    List <IntentMessage> messages = intent.IntentMessages.ToList();
                    if (messages.Count == 0)
                    {
                        return(null);
                    }

                    List <int> readedIds = db.IntentMessagesReads.Where(x => x.UserId == userId).Select(x => x.IntentMessageId).ToList();
                    //Never Read
                    List <IntentMessage> unreadMessages = messages.Where(x => !readedIds.Contains(x.Id)).ToList();
                    if (unreadMessages.Count > 0)
                    {
                        newMessage = GetRandomMessage(unreadMessages);
                        db.IntentMessagesReads.Add(new IntentMessagesRead()
                        {
                            IntentMessageId = newMessage.Id,
                            UserId          = userId,
                            ReadSecond      = false
                        });
                        db.SaveChanges();
                        return(new IntentMessageModel()
                        {
                            Mesasge = newMessage.Message,
                            ShouldEndSession = intent.ShouldEndSession
                        });
                    }
                    ;

                    //Not 2 times read
                    unreadMessages = messages.Where(x => x.IntentMessagesReads.Any(y => y.UserId == userId && y.ReadSecond == false)).ToList();
                    if (unreadMessages.Count > 0)
                    {
                        newMessage = GetRandomMessage(unreadMessages);
                        IntentMessagesRead readedMessage = db.IntentMessagesReads.FirstOrDefault(x => x.IntentMessageId == newMessage.Id);
                        if (readedMessage != null)
                        {
                            readedMessage.ReadSecond = true;
                            db.SaveChanges();
                        }
                        return(new IntentMessageModel()
                        {
                            Mesasge = newMessage.Message,
                            ShouldEndSession = intent.ShouldEndSession
                        });
                    }

                    //All read 2 times
                    newMessage = GetRandomMessage(messages);
                    List <int> messageIds = messages.Select(person => person.Id).ToList();


                    List <IntentMessagesRead> readedMessages = db.IntentMessagesReads.Where(x => x.UserId == userId && messageIds.Contains(x.IntentMessageId)).ToList();
                    foreach (IntentMessagesRead readedMessage in readedMessages)
                    {
                        if (newMessage.Id != readedMessage.IntentMessageId)
                        {
                            readedMessage.ReadSecond = false;
                        }
                    }
                    db.SaveChanges();


                    return(new IntentMessageModel()
                    {
                        Mesasge = newMessage.Message,
                        ShouldEndSession = intent.ShouldEndSession
                    });
                }
            }
            return(null);
        }