Ejemplo n.º 1
0
        public IActionResult AddRecord(string name, string email, string phone, string date, string time, int service_id)
        {
            ServiceOutput service = dbService.GetServiceById(service_id);
            string        address = service.Address;
            int           recordId;

            try
            {
                List <User> users = dbService.GetUsersByEmailAndPhone(email, phone);
                if (users.Count > 0)
                {
                    recordId = dbService.AddRecord(users[0].Id, service_id, address, time, date);
                }
                else
                {
                    int id = dbService.AddUser(name, email, phone);
                    recordId = dbService.AddRecord(id, service_id, address, time, date);
                }
                Console.WriteLine(recordId);
                return(Json(new { result = "success", record_id = recordId.ToString() }));
            }
            catch (Exception)
            {
                return(Json(new { result = "failed" }));
            }
        }
Ejemplo n.º 2
0
 public IActionResult GetTimes(int id, string date)
 {
     try
     {
         if (!(date is null))
         {
             ServiceOutput service = dbService.GetServiceById(id);
             DateTime      dateDT  = DateTime.Parse(date);
             if ((dateDT.CompareTo(DateTime.Now) > 0) || (dateDT.Equals(DateTime.Now.Date)))
             {
                 if (service.Days.ToList().Contains(dateDT.DayOfWeek.ToString()) && (!service.DaysOff.ToList().Contains(DateTime.Parse(date).ToString("dd-MM-yyyy"))) && (DateTime.Parse(service.EndDate).CompareTo(dateDT) > 0))
                 {
                     return(Json(new
                     {
                         result = "success",
                         times = dbService.GetTimesByDateAndServiceId(dateDT.Date.ToString(), id)
                     }));
                 }
             }
         }
         return(Json(new { result = "failed" }));
     }
     catch (Exception)
     {
         return(Json(new { result = "failed" }));
     }
 }
Ejemplo n.º 3
0
        public void ParseCommandMessage(MessageContext context,
                                        string message)
        {
            if (!IsCommandMessage(message))
            {
                return;
            }

            message = message.Substring(1).Trim();
            int    index = message.IndexOf(' ');
            string commandName;
            string commandParams = "";

            if (index != -1)
            {
                commandName   = message.Substring(0, index).Trim();
                commandParams = message.Substring(index).Trim();
            }
            else
            {
                commandName = message.Trim();
            }
            commandName = commandName.ToLower();

            foreach (CommandBuilder command in Commands)
            {
                if (command.Name == commandName)
                {
                    //Create a new instance of the required command type
                    Command cmd = command.CreateCommand();

                    cmd.TechBot    = this;
                    cmd.Context    = context;
                    cmd.Parameters = commandParams;

                    try
                    {
                        cmd.Initialize();
                        cmd.Run();
                        cmd.DeInitialize();
                    }
                    catch (Exception e)
                    {
                        ServiceOutput.WriteLine(context, string.Format("Uops! Just crashed with exception '{0}' at {1}",
                                                                       e.Message,
                                                                       e.Source));

                        ServiceOutput.WriteLine(context, e.StackTrace);
                    }

                    return;
                }
            }
        }
Ejemplo n.º 4
0
        public IActionResult UpdateService(int id)
        {
            ServiceOutput service = dbService.GetServiceById(id);

            ViewBag.Service   = service;
            ViewBag.Addresses = dbService.GetCompanyAddressesByEmail(User.Identity.Name);
            ViewBag.DaysTimes = dbService.GetDaysTimesByServiceId(id);
            string datesOff = "";

            foreach (DayOff dayOff in dbService.GetDaysOffByServiceId(id))
            {
                datesOff += dayOff.Date + ',';
            }
            ViewBag.DatesOff = datesOff.Substring(0, datesOff.Length - 1);
            return(View(ViewBag));
        }
        /// <summary>
        /// The PrepareOutputMessage
        /// </summary>
        /// <param name="items">The items<see cref="List{Item}"/></param>
        /// <param name="coreMessage">The coreMessage<see cref="CoreMessage"/></param>
        /// <returns>The <see cref="IntegrationEvent"/></returns>
        private IntegrationEvent PrepareOutputMessage(IEnumerable <Item> items, CoreMessage coreMessage)
        {
            Dictionary <string, object> properties       = GetUserProperties(coreMessage);
            IntegrationEvent            integrationEvent = GetIntegrationEvent(coreMessage);


            ServiceOutput serviceOutput = new ServiceOutput();

            IEnumerable <Item> result = items.Select(s => new Item
            {
                ItemId          = s.ItemId,
                InlineData      = s.InlineData,
                SourceLabel     = s.SourceLabel,
                ItemPath        = s.ItemPath,
                SourceReference = SourceReference(properties),
                ItemLocation    = BusinessValidationConstants.EXTERNAL,
                ItemType        = BusinessValidationConstants.EXTERNALINTERFACE
            });

            serviceOutput.Items = result.ToList();
            integrationEvent.Body.ServiceOutput = serviceOutput;
            return(integrationEvent);
        }
Ejemplo n.º 6
0
        // TODO: доработать
        public ServiceOutput GetServiceById(int id)
        {
            Service service = db.Services.Find(id);

            if (!(service is null))
            {
                ServiceOutput serviceOut = new ServiceOutput {
                    Id          = service.Id,
                    Company_id  = service.Company_id,
                    Name        = service.Name,
                    Description = service.Description,
                    Long_time   = service.Long_time,
                    Price       = service.Price,
                    Address     = db.Company_to_address.Find(service.Address_id).Address,
                    Days        = db.Service_to_time.Where(item => item.Service_id == service.Id && item.Status.Equals("new")).Select(item => item.Day).Distinct().ToArray(),
                    Times       = db.Service_to_time.Where(item => item.Service_id == service.Id && item.Status.Equals("new")).Select(item => item.Time).ToArray(),
                    DaysOff     = db.Days_off.Where(item => item.Service_id == service.Id).Select(item => item.Date).ToArray(),
                    EndDate     = service.EndDate
                };
                return(serviceOut);
            }
            return(null);
        }
Ejemplo n.º 7
0
 private protected void OnServiceOutput(string message)
 {
     ServiceOutput?.Invoke(this, new ServiceOutputEventArgs(message));
 }
Ejemplo n.º 8
0
        public string SerializeToXML(ServiceOutput obj)
        {
            XmlDocument doc = new XmlDocument();
            XmlSerializer serializer = new XmlSerializer(obj.GetType());
            MemoryStream stream = new MemoryStream();

            try
            {
                serializer.Serialize(stream, obj);
                stream.Position = 0;
                doc.Load(stream);
                return doc.InnerXml;
            }
            catch
            {
                throw;
            }

            finally
            {
                stream.Close();
                stream.Dispose();
            }
        }