Ejemplo n.º 1
0
        public Boolean findPharmByIdAndUpdate(int id, PharmDetail newPharm)
        {
            Boolean            updated = false;
            List <PharmDetail> _pharms = this.getPharms();

            foreach (PharmDetail phar in _pharms)
            {
                if (phar.id == id)
                {
                    phar.name        = newPharm.name;
                    phar.price       = newPharm.price;
                    phar.count       = newPharm.count;
                    phar.description = newPharm.description;
                    updated          = true;
                }
            }
            ;

            if (updated)
            {
                this.saveAll(_pharms);
            }

            return(updated);
        }
Ejemplo n.º 2
0
// POST[ '/api/person' ]
        public void savePharm(PharmDetail newPharm)
        {
            List <PharmDetail> pharms = this.getPharms();

            pharms.Add(newPharm);
            this.saveAll(pharms);
        }
Ejemplo n.º 3
0
        public JsonResult Get(int id)
        {
            PharmDetail newPharm = this.getOnePharm(id);

            if (newPharm != null)
            {
                return(new JsonResult(newPharm));
            }
            else
            {
                return(new JsonResult(new { status = 404, message = "Pharm not found (" }));
            }
        }
Ejemplo n.º 4
0
        public JsonResult Post([FromBody] PharmDetail obj)
        {
            PharmDetail newPharm = new PharmDetail {
                id          = this.countPharms() + 1,
                name        = obj.name,
                price       = obj.price,
                count       = obj.count,
                description = obj.description,
            };

            this.savePharm(newPharm);

            return(Json(new { success = true, newPharm = newPharm, msg = "Pharm successfully added !!!" }));
        }
Ejemplo n.º 5
0
        public JsonResult Put(int id, [FromBody] PharmDetail pharm)
        {
            Boolean success = this.findPharmByIdAndUpdate(id, pharm);

            return(Json(new { success = success }));
        }