Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public async Task <NegoBarangResponse> GetAllASK(string search, string order, string orderDir, int startRec, int pageSize, int draw, string userName)
        {
            NegoBarangResponse resp       = new NegoBarangResponse();
            UserProfile        usrProfile = iTrans.GetUserProfile(userName).Result;
            UserDetail         usrDetail  = iTrans.GetUserDetail(usrProfile.Id).Result;

            if (usrDetail != null)
            {
                if (usrDetail.Description.ToLower() == "admin")
                {
                    resp = await dep.GetAllASK(search, order, orderDir, startRec, pageSize, draw);
                }
                else
                {
                    resp = await dep.GetAllASK(search, order, orderDir, startRec, pageSize, draw, usrProfile.Id);
                }
                resp.IsSuccess = true;
                resp.Message   = "Success";
            }
            else if (usrProfile != null)
            {
                resp = await dep.GetAllASK(search, order, orderDir, startRec, pageSize, draw, usrProfile.Id);

                resp.IsSuccess = true;
                resp.Message   = "Success";
            }
            else
            {
                resp.IsSuccess = false;
                resp.Message   = "Expired Token !";
            }


            return(resp);
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public async Task <NegoBarangResponse> GetAllASK([FromBody] DTParameters param)
        {
            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);
                }
                string search   = HttpContext.Request.Query["search[value]"].ToString();
                int    draw     = param.Draw;
                string order    = param.Order[0].Column.ToString();
                string orderDir = param.Order[0].Dir.ToString();
                int    startRec = param.Start;
                int    pageSize = param.Length;
                resp = await facade.GetAllASK(search, order, orderDir, startRec, pageSize, draw, username);


                return(resp);
            }
            catch (Exception)
            {
                return(resp);
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public async Task <NegoBarangResponse> GetAllBID(string search, string order, string orderDir, int startRec, int pageSize, int draw, long KotaID)
        {
            NegoBarangResponse response = new NegoBarangResponse();

            if (db != null)
            {
                try
                {
                    var query = (from negoBarang in db.NegoBarang
                                 join barang in db.Barang
                                 on negoBarang.BarangId equals barang.Id
                                 join warna in db.Warna
                                 on barang.WarnaId equals warna.Id
                                 join tBarang in db.TypeBarang
                                 on barang.TypeBarangId equals tBarang.Id
                                 join mdlBarang in db.ModelBarang
                                 on tBarang.ModelBarangId equals mdlBarang.Id
                                 join merkBarang in db.Merk
                                 on mdlBarang.MerkId equals merkBarang.Id
                                 where negoBarang.RowStatus == true &&
                                 barang.RowStatus == true &&
                                 warna.RowStatus == true &&
                                 tBarang.RowStatus == true &&
                                 mdlBarang.RowStatus == true &&
                                 merkBarang.RowStatus == true &&
                                 negoBarang.TypePenawaran.ToLower() == "BID" &&
                                 barang.KotaId == KotaID &&
                                 negoBarang.HasTransaction != true
                                 select new
                    {
                        negoBarang.Id,
                        NamaBarang = (merkBarang.Name + " " + mdlBarang.Name + " " + tBarang.Name + " " + warna.Name),
                        negoBarang.Created,
                        negoBarang.CreatedBy,
                        negoBarang.Modified,
                        negoBarang.ModifiedBy,
                        negoBarang.RowStatus,
                        barang.HargaOtr,
                        negoBarang.Harga,
                        MerkID = merkBarang.Id,
                        ModelBarangID = mdlBarang.Id,
                        TypeBarangID = tBarang.Id,
                        WarnaID = warna.Id,
                        barangID = barang.Id,
                        negoBarang.UserProfileId,
                    });
                    int totalRecords = query.Count();
                    if (!string.IsNullOrEmpty(search) && !string.IsNullOrWhiteSpace(search))
                    {
                        query = query.Where(p => p.NamaBarang.ToString().ToLower().Contains(search.ToLower()) ||
                                            p.HargaOtr.ToString().ToLower().Contains(search.ToLower()) ||
                                            p.Harga.ToString().ToLower().Contains(search.ToLower()));
                    }

                    //response = SortByColumnWithOrder(order, orderDir, response);

                    int recFilter = query.Count();

                    response.ListModel = await(from q in query
                                               select new NegoBarangViewModel
                    {
                        ID            = q.Id,
                        Harga         = q.Harga,
                        HargaOTR      = q.HargaOtr,
                        NamaBarang    = q.NamaBarang,
                        MerkID        = q.MerkID,
                        ModelBarangID = q.ModelBarangID,
                        TypeBarangID  = q.TypeBarangID,
                        WarnaID       = q.WarnaID,
                        BarangID      = q.barangID,
                        UserProfileID = q.UserProfileId
                    }

                                               ).Skip(startRec).Take(pageSize).ToListAsync();

                    response.draw            = Convert.ToInt32(draw);
                    response.recordsTotal    = totalRecords;
                    response.recordsFiltered = recFilter;
                    response.Message         = "Success";
                }
                catch (Exception ex)
                {
                    response.Message   = ex.ToString();
                    response.IsSuccess = false;
                }
            }
            return(response);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }