public async Task <IHttpActionResult> PutInfoHospital(int id, InfoHospital infoHospital)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != infoHospital.IDInfoHospital)
            {
                return(BadRequest());
            }

            db.Entry(infoHospital).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InfoHospitalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PutRegister(int id, Register register)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != register.IDRegister)
            {
                return(BadRequest());
            }

            db.Entry(register).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RegisterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public async Task <IHttpActionResult> PutPosition(int id, Position position)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != position.IDPosition)
            {
                return(BadRequest());
            }

            db.Entry(position).State = EntityState.Modified;

            try
            {
                return(Ok(await db.SaveChangesAsync() > 0));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PositionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Пример #4
0
        public async Task <IHttpActionResult> PostLichLamViec(LichLamViec LichLamViec)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.LichLamViecs.Add(LichLamViec);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (LichLamViecExists(LichLamViec.IDLich))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
        public async Task <IHttpActionResult> PutHistoryKhamBenh(int id, HistoryKhamBenh historyKhamBenh)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != historyKhamBenh.IDHistory)
            {
                return(BadRequest());
            }

            db.Entry(historyKhamBenh).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HistoryKhamBenhExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #6
0
        public async Task <IHttpActionResult> PutChuyenKhoa(int id, ChuyenKhoa chuyenKhoa)
        {
            if (id != chuyenKhoa.IDChuyenKhoa)
            {
                return(BadRequest());
            }

            db.Entry(chuyenKhoa).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ChuyenKhoaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #7
0
        public async Task <IHttpActionResult> ChangeAvatar(int id)
        {
            var acc = LoginHelper.GetAccount();

            if (string.IsNullOrWhiteSpace(acc.POSITION) && acc.IDAccount != id)
            {
                return(NotFound());
            }

            var account = db.Accounts.Find(id);

            if (account != null)
            {
                var save = UploadHelper.SaveImage();
                if (save.Key)
                {
                    account.Avatar          = save.Value;
                    db.Entry(account).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(Ok(account.Avatar));
                }
                return(Content(HttpStatusCode.NotAcceptable, save.Key));
            }
            return(BadRequest());
        }
Пример #8
0
        public async Task <IHttpActionResult> Login([FromUri] string Username, [FromUri] string Password)
        {
            Account_BenhNhan account = await db.Account_BenhNhan.FirstOrDefaultAsync(q => q.Username == Username && q.Password == Password && q.Status == ACTIVE);

            if (account == null)
            {
                return(NotFound());
            }

            var time       = TimeSpan.FromHours(10);
            var Expiration = DateTime.Now.Add(time);

            account.TokenExpiration = Expiration;

            var token = Convert.ToBase64String(new UTF8Encoding().GetBytes($"BN:{account.IDAccountBN}:{Username}:{Password}:{Expiration}:{new Random().Next(1000, 9999)}"));

            token         = token.CreateMD5();
            account.Token = token;

            if (await db.SaveChangesAsync() > 0)
            {
                token = $"{account.IDAccountBN}:{token}";
                token = Convert.ToBase64String(new UTF8Encoding().GetBytes(token));
                return(Ok(token));
            }
            return(BadRequest());
        }
        public async Task <IHttpActionResult> ChangeAvatar(int id)
        {
            var acc = LoginHelper.GetAccount();

            if (acc.IDAccountBN != id)
            {
                return(NotFound());
            }

            var Account_BenhNhan = db.Account_BenhNhan.Find(id);

            if (Account_BenhNhan != null)
            {
                var save = UploadHelper.SaveImage();
                if (save.Key)
                {
                    db.Entry(Account_BenhNhan).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(Ok());
                }
                return(Content(HttpStatusCode.NotAcceptable, save.Key));
            }
            return(BadRequest());
        }
        public async Task <IHttpActionResult> PutCTToaThuoc(int id, CTToaThuoc cTToaThuoc)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cTToaThuoc.IDCT)
            {
                return(BadRequest());
            }

            db.Entry(cTToaThuoc).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CTToaThuocExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #11
0
        public async Task <IHttpActionResult> Register(Account account)
        {
            var acc = await db.Accounts.FirstOrDefaultAsync(q => q.Username == account.Username && q.Status == ACTIVE);

            if (acc == null)
            {
                account.Status = CONFIRM;
                db.Accounts.Add(account);
                await db.SaveChangesAsync();

                string urlConfirm = $"{account.IDAccount}:{account.Username}:{account.Email}";
                urlConfirm = Convert.ToBase64String(Encoding.UTF8.GetBytes(urlConfirm));
                urlConfirm = "http://" + Request.RequestUri.Authority + Url.Route("Custom", new { action = "Confirm", id = urlConfirm });

                MailHelper.SendMail(account.Email, "Xác nhận", $"<a href='{urlConfirm}'>Bấm để xác nhận Confirm</a>");

                return(Ok(urlConfirm));
            }
            else
            {
                return(Content(HttpStatusCode.NotAcceptable, "Tài khoản đã tồn tại"));
            }
        }