Ejemplo n.º 1
0
        /// <summary>
        /// Add the specified client.
        /// </summary>
        /// <param name="model">Model.</param>
        public ClientViewModel Add(ClientViewModel model)
        {
            Clients client = new Clients()
            {
                Id = GetNewId(),
                Name_surname = model.NameSurname,
                Id_number = model.IdNumber,
                Company = model.Company == "" ? null : model.Company,
                Room_number = model.RoomNumber,
                Is_here = model.IsHere ? 1 : 0,
                Vegetarian = model.Vegetarian ? 1 : 0,
                Questionnaire = model.Questionnaire ? 1 : 0,
                Invoice = model.Invoice ? 1 : 0,
            };

            _context.Clients.Add(client);
            _context.SaveChanges();

            model.Id = client.Id;

            return model;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update the client with specified model.
        /// </summary>
        /// <param name="model">Model.</param>
        public ClientViewModel Update(ClientViewModel model)
        {
            var client = _context.Clients.Single(x => x.Id == model.Id);
            client.Name_surname = model.NameSurname;
            client.Id_number = model.IdNumber;
            client.Company = model.Company == "" ? null : model.Company;
            client.Room_number = model.RoomNumber;
            client.Is_here = model.IsHere ? 1 : 0;
            client.Vegetarian = model.Vegetarian ? 1 : 0;
            client.Questionnaire = model.Questionnaire ? 1 : 0;
            client.Invoice = model.Invoice ? 1 : 0;
            _context.SaveChanges();

            return model;
        }
Ejemplo n.º 3
0
        public InvoiceViewModel GetInvoice(ClientViewModel client)
        {
            var roomId = (Guid)client.RoomNumber;
            var roomPrice = _context.Rooms.First(x => x.Id == roomId).Price;

            var treatmentsHistory = _context.TreatmentsHistory.Where(x => x.Client_id == client.Id).ToList();

            double treatmentsPrice = 0;
            foreach(var th in treatmentsHistory){
                var treatmentPrice = _context.Treatments.First(x => x.Id == th.Treatment_id).Price;
                treatmentsPrice += treatmentPrice;
            }

            var price = roomPrice + treatmentsPrice;

            return new InvoiceViewModel {
                ClientNameSurname = client.NameSurname,
                Company = client.Company,
                Price = price
            };
        }
Ejemplo n.º 4
0
        public ClientViewModel PutVeg(Guid id, ClientViewModel model)
        {
            if (ModelState.IsValid)
            {
                var client = CheckIfClientExists(id);

                try
                {
                    client.Vegetarian = model.Vegetarian;
                }
                catch (NullReferenceException)
                {
                    throw new HttpResponseException(new HttpResponseMessage
                    {
                        StatusCode = HttpStatusCode.BadRequest,
                        Content = new StringContent("Can't change when option 'Vegetarian' is empty.")
                    });
                }
                return _repository.Update(client);
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
Ejemplo n.º 5
0
        public Clients PutQuest(Guid id, ClientViewModel model)
        {
            if (ModelState.IsValid)
            {
                var client = CheckIfClientExists(id);

                try
                {
                    client.Questionnaire = model.Questionnaire;
                }
                catch (NullReferenceException)
                {
                    throw new HttpResponseException(new HttpResponseMessage
                    {
                        StatusCode = HttpStatusCode.BadRequest,
                        Content = new StringContent("Can't change when option 'Questionnaire' is empty.")
                    });
                }
                return _repository.ChangeQuestStatus(id, model.Questionnaire);
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
Ejemplo n.º 6
0
        public ClientViewModel Put(Guid id, ClientViewModel model)
        {
            CheckIfClientExists(id);

            model.Id = id;
            return _repository.Update(model);
        }
Ejemplo n.º 7
0
        public HttpResponseMessage Post(ClientViewModel model)
        {
            if (ModelState.IsValid)
            {
                ClientViewModel client;
                try
                {
                     client = _repository.Add(model);
                }
                catch (NullReferenceException)
                {
                    throw new HttpResponseException(new HttpResponseMessage
                    {
                        StatusCode = HttpStatusCode.NotFound,
                        Content = new StringContent("Can't add undefined object")
                    });
                }

                var response = Request.CreateResponse<ClientViewModel>(HttpStatusCode.Created, client);

                string uri = Url.Link("DefaultApi", new { id = model.Id });
                response.Headers.Location = new Uri(uri);
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }