public async Task <IActionResult> Edit(string id, [Bind("medicineTypeId,medicineTypeName")] MedicineType medicineType)
        {
            if (id != medicineType.medicineTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(medicineType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MedicineTypeExists(medicineType.medicineTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(medicineType));
        }
Exemplo n.º 2
0
 public Medicine(string name, double price, string expirationDate, MedicineType type)
 {
     _name           = name;
     _price          = price;
     _expirationDate = expirationDate;
     _type           = type;
 }
Exemplo n.º 3
0
        private async void btnCreateType_Click(object sender, EventArgs e)
        {
            string TypeName = txtCreateType.Text.Trim();

            if (TypeName == "")
            {
                MessageBox.Show("The field must be filled", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_db.MedicineTypes.Any(t => t.typeName == TypeName))
            {
                MessageBox.Show("This type is already exist", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            MedicineType type = new MedicineType
            {
                typeName = TypeName
            };

            _db.MedicineTypes.Add(type);
            await _db.SaveChangesAsync();

            this.Close();
        }
 public ActionResult MedicineType(MedicineType objMedicineType)
 {
     try
     {
         if (dbunit.CheckMedicineType(objMedicineType.MedicineTypeID, objMedicineType.MedicineTypeName))
         {
             if (dbunit.Save(objMedicineType))
             {
                 if (objMedicineType.MedicineTypeID > 0)
                 {
                     ModelState.Clear();
                     TempData["msg"] = "Medicine Type Update Successfully";
                     return(RedirectToAction("MedicineType", "MedicineType"));
                 }
                 else
                 {
                     ModelState.Clear();
                     TempData["msg"] = "Medicine Type Saved Successfully";
                     return(RedirectToAction("MedicineType", "MedicineType"));
                 }
             }
         }
         else
         {
             TempData["msg"] = "MedicineType Already Exist's";
             return(RedirectToAction("MedicineType", "MedicineType"));
         }
         return(View());
     }
     catch (Exception ex)
     {
         TempData["msg"] = ex.Message;
         return(RedirectToAction("MedicineType", "MedicineType"));
     }
 }
Exemplo n.º 5
0
        public IActionResult Update([FromRoute] int id, [FromBody] MedicineType medicineType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != medicineType.TypeCode)
            {
                return(BadRequest());
            }

            _medicineService.Update(medicineType);

            try
            {
                _medicineService.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (Get(id) == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 6
0
 public Medicine(long id, string name, double strength, MedicineType medicineType, bool isValid, List <Disease> usedFor, List <Ingredient> ingredient, int inStock, int minNumber) : base(id, name, inStock, minNumber)
 {
     _strength     = strength;
     _medicineType = MedicineType;
     _isValid      = isValid;
     _ingredient   = ingredient;
     _usedFor      = usedFor;
 }
Exemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            MedicineType medicineType = db.MedicineType.Find(id);

            db.MedicineType.Remove(medicineType);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 8
0
 public MedicineFilter(Disease disease, string name, MedicineType medicineType, Ingredient ingredient, double strength)
 {
     _disease    = disease;
     _name       = name;
     _type       = medicineType;
     _ingredient = ingredient;
     _strength   = strength;
 }
Exemplo n.º 9
0
 public Medicine(string name, double strength, MedicineType medicineType, int inStock, int minNumber) : base(name, inStock, minNumber)
 {
     _strength     = strength;
     _medicineType = MedicineType;
     _isValid      = false;
     _ingredient   = new List <Ingredient>();
     _usedFor      = new List <Disease>();
 }
Exemplo n.º 10
0
        public async Task <IActionResult> Delete(int id)
        {
            MedicineType medicineType = await medicineTypeRepository.Get(id).ConfigureAwait(true);

            medicineTypeRepository.Remove(medicineType);
            await unitOfWork.CompleteAsync().ConfigureAwait(true);

            return(Ok(mapper.Map <MedicineTypeForGetDTO>(medicineType)));
        }
Exemplo n.º 11
0
 public IActionResult Put([FromBody] MedicineType medicineType)
 {
     DbContext.MedicineTypes.Add(medicineType);
     DbContext.SaveChanges();
     return(new JsonResult(medicineType, new JsonSerializerSettings()
     {
         Formatting = Formatting.Indented
     }));
 }
Exemplo n.º 12
0
        public async Task <IActionResult> Put(MedicineTypeForEditDTO model)
        {
            MedicineType medicineType = mapper.Map <MedicineType>(model);

            medicineTypeRepository.Edit(medicineType);
            await unitOfWork.CompleteAsync().ConfigureAwait(true);

            return(Ok(mapper.Map <MedicineTypeForGetDTO>(await medicineTypeRepository.Get(medicineType.Id).ConfigureAwait(true))));
        }
Exemplo n.º 13
0
        private async void btnDeleteType_Click(object sender, EventArgs e)
        {
            int          Id   = ((CmbTypes)cmbTypes.SelectedItem).Id;
            MedicineType type = _db.MedicineTypes.Find(Id);

            type.Deleted = true;
            await _db.SaveChangesAsync();

            this.Close();
        }
Exemplo n.º 14
0
 public ActionResult Edit([Bind(Include = "ID,Name")] MedicineType medicineType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(medicineType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(medicineType));
 }
        public async Task <IActionResult> Edit(MedicineType MedicineType)
        {
            if (ModelState.IsValid)
            {
                _db.Update(MedicineType);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(MedicineType));
        }
        public async Task <IActionResult> Create([Bind("medicineTypeId,medicineTypeName")] MedicineType medicineType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(medicineType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(medicineType));
        }
Exemplo n.º 17
0
        public ActionResult Create([Bind(Include = "ID,Name")] MedicineType medicineType)
        {
            if (ModelState.IsValid)
            {
                db.MedicineType.Add(medicineType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(medicineType));
        }
Exemplo n.º 18
0
        public IActionResult GetMedicines()
        {
            Logger.LogInformation($"{nameof(OntologyController)}.{nameof(GetMedicines)}: Start.");

            var result = MedicineType.GetList()
                         .Select(x => new TypeViewModel {
                Id = x.Id, Name = x.Name, Description = x.Description
            });

            Logger.LogInformation($"{nameof(OntologyController)}.{nameof(GetMedicines)}: End.");
            return(new OkResponseResult("Medicines", new { Medicines = result }));
        }
Exemplo n.º 19
0
        public IActionResult Add([FromBody] MedicineType medicineType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _medicineService.Add(medicineType);
            _medicineService.Save();

            return(CreatedAtAction("Get", new { id = medicineType.TypeCode }, medicineType));
        }
        public void AddMedicineType(string type)
        {
            MedicineType ob = new MedicineType();

            ob.Name = type;

            using (var context = new CBContext())
            {
                context.Types.Add(ob);
                context.SaveChanges();
            }
        }
        public async Task <IActionResult> Add([Required][FromBody] MedicineType medicineType)
        {
            Logger.LogInformation($"Requesting the creation of a new medicine type with details {medicineType}...");

            if (!ModelState.IsValid || medicineType == null)
            {
                return(BadRequest(ModelState));
            }

            var addedItem = await _medicineTypeCrudService.AddAsync(medicineType, RequestAbortToken).ConfigureAwait(false);

            return(CreatedAtAction(nameof(Get), new { id = addedItem.Id }, medicineType));
        }
Exemplo n.º 22
0
        // GET: MedicineTypes/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MedicineType medicineType = db.MedicineType.Find(id);

            if (medicineType == null)
            {
                return(HttpNotFound());
            }
            return(View(medicineType));
        }
 public MedicineInfo(string id, string effect, MedicineType medicineType, string[] curedDiseases = null)
 {
     Debug.Assert(!string.IsNullOrEmpty(effect) || (curedDiseases != null && curedDiseases.Length > 0), "Medicine should have an effect or cure diseases");
     this.id           = id;
     this.effect       = effect;
     this.medicineType = medicineType;
     if (curedDiseases != null)
     {
         curedSicknesses = new List <string>(curedDiseases);
     }
     else
     {
         curedSicknesses = new List <string>();
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            try
            {
                MedicineType medicineType = db.MedicineTypes.Find(id);
                db.MedicineTypes.Remove(medicineType);
                db.SaveChanges();
            }
            catch (Exception)
            {
                return(RedirectToAction("Error", "Home"));
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 25
0
        private void gridView1_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            //Insert, update row
            var  row = (e.Row as System.Data.DataRowView).Row;
            bool result;

            if (gridView1.IsNewItemRow(e.RowHandle))
            {
                //insert
                MedicineType MedicineType = new MedicineType()
                {
                    MedicineTypeName = (string)row["MedicineTypeName"]
                };

                int id = medicineTypeBusiness.Insert(MedicineType);
                if (id == 0)
                {
                    result = false;
                }
                else
                {
                    result = true;
                    row["MedicineTypeID"] = id;
                }
            }
            else
            {
                //update
                MedicineType medicineType = new MedicineType()
                {
                    MedicineTypeID   = (int)row["MedicineTypeID"],
                    MedicineTypeName = (string)row["MedicineTypeName"]
                };

                result = medicineTypeBusiness.Update(medicineType);
            }

            if (result)
            {
                XtraMessageBox.Show(this, "Lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                gridView1.FocusedRowHandle = GridControl.NewItemRowHandle;
            }
            else
            {
                XtraMessageBox.Show(this, "Lưu thất bại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 26
0
        public Medicine ConvertCSVToEntity(string csv)
        {
            string[]          tokens          = SplitStringByDelimiter(csv, _delimiter);
            List <Disease>    dummyDisease    = (tokens[5] == "") ? new List <Disease>() : GetDummyDisease(SplitStringByDelimiter(tokens[5], _listDelimiter));
            List <Ingredient> dummyIngredient = (tokens[6] == "") ? new List <Ingredient>() : GetDummyIngredient(SplitStringByDelimiter(tokens[6], _listDelimiter));
            MedicineType      medicineType    = (MedicineType)Enum.Parse(typeof(MedicineType), tokens[3]); //Casting string to Enum.

            return(new Medicine(
                       long.Parse(tokens[0]),
                       tokens[1],
                       double.Parse(tokens[2]),
                       medicineType,
                       bool.Parse(tokens[4]),
                       dummyDisease,
                       dummyIngredient,
                       int.Parse(tokens[7]),
                       int.Parse(tokens[8])));
        }
Exemplo n.º 27
0
        public IActionResult Post([FromBody] MedicineType value)
        {
            var medicineType = DbContext.MedicineTypes.FirstOrDefault(mt => mt.Id == value.Id);

            if (medicineType == null)
            {
                return(NotFound(new
                {
                    Error = string.Format("Medicine Type with the Id {0} not found", value.Id)
                }));
            }

            medicineType.Type = value.Type;
            DbContext.SaveChanges();

            return(new JsonResult(medicineType, new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            }));
        }
Exemplo n.º 28
0
        public bool Save(MedicineType obj)
        {
            Connect();
            SqlCommand cmd = new SqlCommand("IUMedicineType", con);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@HospitalID", HospitalID);
            cmd.Parameters.AddWithValue("@LocationID", LocationID);
            if (obj.MedicineTypeID == 0)
            {
                cmd.Parameters.AddWithValue("@MedicineTypeID", 0);
                cmd.Parameters.AddWithValue("@Mode", "Add");
            }
            else
            {
                cmd.Parameters.AddWithValue("@MedicineTypeID", obj.MedicineTypeID);
                cmd.Parameters.AddWithValue("@Mode", "Edit");
            }
            if (obj.MedicineTypeName == null)
            {
                cmd.Parameters.AddWithValue("@MedicineTypeName", 0);
            }
            else
            {
                cmd.Parameters.AddWithValue("@MedicineTypeName", obj.MedicineTypeName);
            }

            cmd.Parameters.AddWithValue("@CreationID", UserID);
            con.Open();
            int i = cmd.ExecuteNonQuery();

            con.Close();
            if (i > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 29
0
        public IActionResult Patch([FromRoute] int id, [FromBody] MedicineType medicineType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != medicineType.TypeCode)
            {
                return(BadRequest());
            }


            MedicineType updatedMedicineType = null;

            try
            {
                _medicineService.Update(medicineType);
                _medicineService.Save();
                updatedMedicineType = _medicineService.Get(medicineType.TypeCode);
            }
            catch (EntityNotFoundException <MedicineType> ex)
            {
                return(NotFound(ex.Message));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (updatedMedicineType == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(updatedMedicineType));
        }
Exemplo n.º 30
0
 private ISpecification <Medicine> GetSpecificationByType(MedicineType type)
 {
     return(new ExpressionSpecification <Medicine>(o => o.MedicineType.Equals(type)));
 }