示例#1
0
        public ContentResult AddService(Uslugis service)
        {
            string json;

            ModelState.Clear();

            if (TryValidateModel(service))
            {
                var id = _servicesRepository.CreateService(service);

                json = JsonConvert.SerializeObject(new
                {
                    id      = id,
                    success = true,
                    message = "Post added successfully."
                });
            }
            else
            {
                json = JsonConvert.SerializeObject(new
                {
                    id      = 0,
                    success = false,
                    message = "Failed to add the post."
                });
            }

            return(Content(json, "application/json"));
        }
示例#2
0
        public ContentResult EditServices(Uslugis service)
        {
            string json;

            if (ModelState.IsValid)
            {
                _servicesRepository.CreateService(service);
                json = JsonConvert.SerializeObject(new
                {
                    id      = service.id,
                    success = true,
                    message = "Changes saved successfully."
                });
            }
            else
            {
                json = JsonConvert.SerializeObject(new
                {
                    id      = 0,
                    success = false,
                    message = "Failed to save the changes."
                });
            }

            return(Content(json, "application/json"));
        }
示例#3
0
        public Guid CreateService(Uslugis uslugis)
        {
            if (uslugis.id == Guid.Empty)
            {
                uslugis.id = Guid.NewGuid();


                // post.Category = null;
                context.Uslugis.Add(uslugis);
                context.SaveChanges();
            }
            else
            {
                //  post.Category = null;

                context.Entry(uslugis).State = EntityState.Modified;
                context.SaveChanges();
            }
            return(uslugis.id);;
        }