Example #1
0
        public async Task <NegoBarangResponse> UpdatePost(NegoBarangRequest model)
        {
            NegoBarangResponse response = new NegoBarangResponse();

            if (db != null)
            {
                try
                {
                    NegoBarang negoBarang = await db.NegoBarang.Where(x => x.RowStatus == true && x.Id == model.ID).FirstOrDefaultAsync();

                    if (negoBarang != null)
                    {
                        negoBarang.UserProfileId = model.UserProfileID;
                        negoBarang.BarangId      = model.BarangID;
                        negoBarang.TypePenawaran = model.TypePenawaran;
                        negoBarang.Harga         = model.Harga;
                        negoBarang.Modified      = DateTime.Now;
                        negoBarang.ModifiedBy    = model.ModifiedBy;
                        await db.SaveChangesAsync();
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message   = "Data Not Found";
                    }
                }
                catch (Exception ex)
                {
                    response.Message   = ex.ToString();
                    response.IsSuccess = false;
                }
            }
            return(response);
        }
Example #2
0
        public async Task <NegoBarangResponse> GetPost(NegoBarangRequest req)
        {
            NegoBarangResponse response = new NegoBarangResponse();

            if (db != null)
            {
                try
                {
                    response.ListModel = await(from model in db.NegoBarang
                                               where model.RowStatus == true && model.Id == req.ID
                                               select new NegoBarangViewModel
                    {
                        ID            = model.Id,
                        UserProfileID = model.UserProfileId,
                        BarangID      = model.BarangId,
                        TypePenawaran = model.TypePenawaran,
                        Harga         = model.Harga,
                        Created       = model.Created,
                        CreatedBy     = model.CreatedBy,
                        Modified      = model.Modified,
                        ModifiedBy    = model.ModifiedBy,
                        RowStatus     = model.RowStatus
                    }).ToListAsync();
                }
                catch (Exception ex)
                {
                    response.Message = ex.ToString();
                }
            }

            return(response);
        }
Example #3
0
        public async Task <NegoBarangResponse> AddPost(NegoBarangRequest model)
        {
            NegoBarangResponse response = new NegoBarangResponse();


            if (db != null)
            {
                try
                {
                    NegoBarang negoBarang = new NegoBarang();

                    negoBarang.UserProfileId = db.UserProfile.Where(x => x.RowStatus == true && x.Email == model.UserName).Select(x => x.Id).FirstOrDefaultAsync().Result;
                    negoBarang.BarangId      = model.BarangID;
                    negoBarang.TypePenawaran = model.TypePenawaran;
                    negoBarang.Harga         = model.Harga;
                    negoBarang.Created       = DateTime.Now;
                    negoBarang.CreatedBy     = model.UserName;
                    negoBarang.RowStatus     = true;

                    await db.NegoBarang.AddAsync(negoBarang);

                    await db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    response.IsSuccess = false;
                    response.Message   = ex.ToString();
                }
            }


            return(response);
        }
Example #4
0
        public async Task <NegoBarangResponse> DeletePost(NegoBarangRequest model)
        {
            NegoBarangResponse response = new NegoBarangResponse();

            if (db != null)
            {
                try
                {
                    NegoBarang negoBarang = await db.NegoBarang.Where(x => x.RowStatus == true && x.Id == model.ID).FirstOrDefaultAsync();

                    if (negoBarang != null)
                    {
                        negoBarang.RowStatus = false;
                        await db.SaveChangesAsync();

                        response.Message = "Data has been Saved";
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message   = "Data Not Found";
                    }
                }
                catch (Exception ex)
                {
                    response.Message   = ex.ToString();
                    response.IsSuccess = false;
                }
            }
            return(response);
        }
Example #5
0
        public async Task <NegoBarangResponse> GetPost(NegoBarangRequest req)
        {
            var model = await dep.GetPost(req);

            if (model == null)
            {
                return(null);
            }
            return(model);
        }
Example #6
0
        public async Task <IActionResult> DeletePost(NegoBarangRequest req)
        {
            try
            {
                var result = await facade.DeletePost(req);

                return(Ok(result));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #7
0
        public async Task <NegoBarangResponse> SubmitAsk([FromBody] NegoBarangRequest request)
        {
            NegoBarangResponse resp = new NegoBarangResponse();

            try
            {
                string bearer   = Request.HttpContext.Request.Headers["Authorization"];
                string token    = bearer.Substring("Bearer ".Length).Trim();
                string username = string.Empty;
                if (string.IsNullOrEmpty(token))
                {
                    resp.IsSuccess = false;
                    resp.Message   = "You don't have access.";
                    return(resp);
                }

                username = sec.ValidateToken(token);
                if (username == null)
                {
                    Response.HttpContext.Response.Cookies.Append("access_token", "", new CookieOptions()
                    {
                        Expires = DateTime.Now.AddDays(-1)
                    });
                    resp.IsSuccess = false;
                    resp.Message   = "Your session was expired, please re-login.";
                    return(resp);
                }
                request.UserName = username;
                resp             = await facade.Submitask(request);

                return(resp);
            }
            catch (Exception)
            {
                return(resp);
            }
            //NegoBarangResponse response = new NegoBarangResponse();
            //try
            //{
            //    response = await facade.Submitask(request);
            //}
            //catch (Exception ex)
            //{
            //    return BadRequest(ex);
            //}
            //return Ok(response);
        }
Example #8
0
        public async Task <IActionResult> GetPost(NegoBarangRequest req)
        {
            if (req == null)
            {
                return(BadRequest());
            }

            try
            {
                var post = await facade.GetPost(req);

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

                return(Ok(post));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #9
0
        public async Task <IActionResult> UpdatePost([FromBody] NegoBarangRequest req)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var result = await facade.UpdatePost(req);

                    return(Ok(result));
                }
                catch (Exception ex)
                {
                    if (ex.GetType().FullName ==
                        "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException")
                    {
                        return(NotFound());
                    }

                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
Example #10
0
        public async Task <NegoBarangResponse> DeletePost(NegoBarangRequest req)
        {
            NegoBarangResponse response = new NegoBarangResponse();

            try
            {
                if (await dep.DeletePost(req.ID))
                {
                    response.IsSuccess = true;
                    response.Message   = "Data Deleted";
                }
                else
                {
                    response.IsSuccess = false;
                    response.Message   = "Delete data Failed";
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = true;
                response.Message   = ex.ToString();
            }
            return(response);
        }
Example #11
0
        public async Task <NegoBarangResponse> SubmitBid(NegoBarangRequest req)
        {
            NegoBarangResponse response    = new NegoBarangResponse();
            NegoBarang         model       = new NegoBarang();
            UserProfile        userProfile = await IAuth.GetUserProfileByEmail(req.UserName);

            try
            {
                if (req.ID > 0)
                {
                    model.Id            = req.ID;
                    model.UserProfileId = userProfile.Id;
                    model.BarangId      = req.BarangID;
                    model.Harga         = req.Harga;
                    model.TypePenawaran = req.TypePenawaran = "BID";
                    model.Created       = DateTime.Now;
                    model.CreatedBy     = req.UserName;
                    model.RowStatus     = true;
                    if (await dep.UpdatePost(model) > 0)
                    {
                        response.IsSuccess = true;
                        response.Message   = "Update Success";
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message   = "Update Failed";
                    }
                }
                else
                {
                    model.UserProfileId = userProfile.Id;
                    model.BarangId      = req.BarangID;
                    model.TypePenawaran = req.TypePenawaran = "BID";
                    model.Created       = DateTime.Now;
                    model.CreatedBy     = req.UserName;
                    model.RowStatus     = true;
                    model.Harga         = req.Harga;

                    if (await dep.AddPost(model) > 0)
                    {
                        response.IsSuccess = true;
                        response.Message   = "Data Already Saved";
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message   = "Save Failed";
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                response.IsSuccess = false;
                response.Message   = ex.Message.ToString();
            }

            //return await dep.AddPost(req);
            return(response);
        }
Example #12
0
        public async Task <NegoBarangResponse> SubmitListASK(NegoBarangRequest req)
        {
            NegoBarangResponse response = new NegoBarangResponse();

            UserProfile userProfile = await IAuth.GetUserProfileByEmail(req.UserName);

            try
            {
                List <Barang> barangs = iBarang.GetIDBarangByTypeAndColourIDS(req.TypeBarangID, req.ListWarna).Result;
                foreach (var item in barangs)
                {
                    NegoBarang model = new NegoBarang();
                    model.Id            = req.ID;
                    model.UserProfileId = userProfile.Id;
                    model.BarangId      = item.Id;
                    model.Harga         = req.Harga;
                    model.TypePenawaran = req.TypePenawaran = "ASK";
                    model.Created       = DateTime.Now;
                    model.CreatedBy     = req.UserName;
                    model.RowStatus     = true;
                    if (await dep.AddPost(model) > 0)
                    {
                        response.IsSuccess = true;
                        response.Message   = "Data Already Success";
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message   = "Save Failed";
                    }
                }
                //if (req.ID > 0)
                //{
                //    model.Id = req.ID;
                //    model.UserProfileId = userProfile.Id;
                //    model.BarangId = req.BarangID;
                //    model.Harga = req.Harga;
                //    model.TypePenawaran = req.TypePenawaran = "ASK";
                //    model.Created = DateTime.Now;
                //    model.CreatedBy = req.UserName;
                //    model.RowStatus = true;
                //    if (await dep.UpdatePost(model) > 0)
                //    {
                //        response.IsSuccess = true;
                //        response.Message = "Update Success";
                //    }
                //    else
                //    {
                //        response.IsSuccess = false;
                //        response.Message = "Update Failed";
                //    }

                //}
                //else
                //{
                //    model.UserProfileId = userProfile.Id;
                //    model.BarangId = req.BarangID;
                //    model.TypePenawaran = req.TypePenawaran = "ASK";
                //    model.Created = DateTime.Now;
                //    model.CreatedBy = req.UserName;
                //    model.RowStatus = true;
                //    model.Harga = req.Harga;
                //    if (await dep.AddPost(model) > 0)
                //    {
                //        response.IsSuccess = true;
                //        response.Message = "Data Already Saved";
                //    }
                //    else
                //    {
                //        response.IsSuccess = false;
                //        response.Message = "Save Failed";
                //    }
                //}
            }
            catch (Exception ex)
            {
                log.Error(ex);
                response.IsSuccess = false;
                response.Message   = ex.Message.ToString();
            }

            //return await dep.AddPost(req);
            return(response);
        }
Example #13
0
 public async Task <NegoBarangResponse> UpdatePost(NegoBarangRequest req)
 {
     return(await dep.UpdatePost(req));
 }
Example #14
0
        public async Task <NegoBarangResponse> Submitask(NegoBarangRequest req)
        {
            NegoBarangResponse response    = new NegoBarangResponse();
            NegoBarang         model       = new NegoBarang();
            UserProfile        userProfile = await IAuth.GetUserProfileByEmail(req.UserName);

            UserDetail userDetail = await IAuth.GetUserDetailByID(userProfile.Id);

            if (userDetail == null)
            {
                response.IsSuccess = false;
                response.Message   = "Pastikan Anda adalah Seller yang terverifikasi";
                return(response);
            }
            if (userDetail.Description == null || userDetail.Description.ToLower() != "seller")
            {
                response.IsSuccess = false;
                response.Message   = "Pastikan Anda adalah Seller yang terverifikasi";
                return(response);
            }
            try
            {
                if (req.ID > 0)
                {
                    model.Id            = req.ID;
                    model.UserProfileId = userProfile.Id;
                    model.BarangId      = req.BarangID;
                    model.Harga         = req.Harga;
                    model.TypePenawaran = req.TypePenawaran = "ASK";
                    model.Created       = DateTime.Now;
                    model.CreatedBy     = req.UserName;
                    model.RowStatus     = true;
                    if (await dep.UpdatePost(model) > 0)
                    {
                        response.IsSuccess = true;
                        response.Message   = "Update Success";
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message   = "Update Failed";
                    }
                }
                else
                {
                    model.UserProfileId = userProfile.Id;
                    model.BarangId      = req.BarangID;
                    model.TypePenawaran = req.TypePenawaran = "ASK";
                    model.Created       = DateTime.Now;
                    model.CreatedBy     = req.UserName;
                    model.RowStatus     = true;
                    model.Harga         = req.Harga;
                    if (await dep.AddPost(model) > 0)
                    {
                        response.IsSuccess = true;
                        response.Message   = "Data Already Saved";
                    }
                    else
                    {
                        response.IsSuccess = false;
                        response.Message   = "Save Failed";
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                response.IsSuccess = false;
                response.Message   = ex.Message.ToString();
            }

            //return await dep.AddPost(req);
            return(response);
        }